diff --git a/lib/ui/huge_listview/lazy_loading_gallery.dart b/lib/ui/huge_listview/lazy_loading_gallery.dart index 04410feee..15a59d467 100644 --- a/lib/ui/huge_listview/lazy_loading_gallery.dart +++ b/lib/ui/huge_listview/lazy_loading_gallery.dart @@ -232,7 +232,12 @@ class _LazyLoadingGalleryState extends State { ) ], ), - _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 { bool _shouldRender; + int _photoGridSize; StreamSubscription _clearSelectionsEvent; @override @@ -334,6 +340,7 @@ class _LazyLoadingGridViewState extends State { @override Widget build(BuildContext context) { + _photoGridSize = LocalSettings.instance.getPhotoGridSize(); if (widget.shouldRecycle) { return _getRecyclableView(); } else { @@ -354,7 +361,7 @@ class _LazyLoadingGridViewState extends State { }, child: _shouldRender ? _getGridView() - : PlaceHolderWidget(widget.filesInDay.length), + : PlaceHolderWidget(widget.filesInDay.length, _photoGridSize), ); } @@ -369,7 +376,7 @@ class _LazyLoadingGridViewState extends State { }); } }, - child: PlaceHolderWidget(widget.filesInDay.length), + child: PlaceHolderWidget(widget.filesInDay.length, _photoGridSize), ); } else { return _getGridView(); @@ -388,7 +395,7 @@ class _LazyLoadingGridViewState extends State { gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisSpacing: 2, mainAxisSpacing: 2, - crossAxisCount: LocalSettings.instance.getPhotoGridSize(), + crossAxisCount: _photoGridSize, ), padding: const EdgeInsets.all(0), ); diff --git a/lib/ui/huge_listview/place_holder_widget.dart b/lib/ui/huge_listview/place_holder_widget.dart index 33ee6cb94..06c0d3342 100644 --- a/lib/ui/huge_listview/place_holder_widget.dart +++ b/lib/ui/huge_listview/place_holder_widget.dart @@ -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 = {}; + static final _gridViewCache = {}; @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(); } }