commit
f9d6b0ca53
|
@ -232,7 +232,12 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
|
|||
)
|
||||
],
|
||||
),
|
||||
_shouldRender ? _getGallery() : PlaceHolderWidget(_files.length),
|
||||
_shouldRender
|
||||
? _getGallery()
|
||||
: PlaceHolderWidget(
|
||||
_files.length,
|
||||
LocalSettings.instance.getPhotoGridSize(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -299,6 +304,7 @@ class LazyLoadingGridView extends StatefulWidget {
|
|||
|
||||
class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
|
||||
bool _shouldRender;
|
||||
int _photoGridSize;
|
||||
StreamSubscription<ClearSelectionsEvent> _clearSelectionsEvent;
|
||||
|
||||
@override
|
||||
|
@ -334,6 +340,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_photoGridSize = LocalSettings.instance.getPhotoGridSize();
|
||||
if (widget.shouldRecycle) {
|
||||
return _getRecyclableView();
|
||||
} else {
|
||||
|
@ -354,7 +361,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
|
|||
},
|
||||
child: _shouldRender
|
||||
? _getGridView()
|
||||
: PlaceHolderWidget(widget.filesInDay.length),
|
||||
: PlaceHolderWidget(widget.filesInDay.length, _photoGridSize),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -369,7 +376,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
|
|||
});
|
||||
}
|
||||
},
|
||||
child: PlaceHolderWidget(widget.filesInDay.length),
|
||||
child: PlaceHolderWidget(widget.filesInDay.length, _photoGridSize),
|
||||
);
|
||||
} else {
|
||||
return _getGridView();
|
||||
|
@ -388,7 +395,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
|
|||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisSpacing: 2,
|
||||
mainAxisSpacing: 2,
|
||||
crossAxisCount: LocalSettings.instance.getPhotoGridSize(),
|
||||
crossAxisCount: _photoGridSize,
|
||||
),
|
||||
padding: const EdgeInsets.all(0),
|
||||
);
|
||||
|
|
|
@ -4,18 +4,20 @@ import 'package:flutter/material.dart';
|
|||
|
||||
class PlaceHolderWidget extends StatelessWidget {
|
||||
const PlaceHolderWidget(
|
||||
this.count, {
|
||||
this.count,
|
||||
this.columns, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
final int count;
|
||||
final int count, columns;
|
||||
|
||||
static final _gridViewCache = <int, GridView>{};
|
||||
static final _gridViewCache = <String, GridView>{};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_gridViewCache.containsKey(count)) {
|
||||
_gridViewCache[count] = GridView.builder(
|
||||
final key = _getCacheKey(count, columns);
|
||||
if (!_gridViewCache.containsKey(key)) {
|
||||
_gridViewCache[key] = GridView.builder(
|
||||
padding: const EdgeInsets.all(0),
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
|
@ -26,11 +28,15 @@ class PlaceHolderWidget extends StatelessWidget {
|
|||
);
|
||||
},
|
||||
itemCount: count,
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 4,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: columns,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _gridViewCache[count];
|
||||
return _gridViewCache[key];
|
||||
}
|
||||
|
||||
String _getCacheKey(int totalCount, int columns) {
|
||||
return totalCount.toString() + ":" + columns.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue