removed keys from slivers to fix rendering order issue

This commit is contained in:
Thibault Deckers 2020-01-02 01:33:58 +09:00
parent adda4be428
commit 01414d96be
3 changed files with 44 additions and 47 deletions

View file

@ -8,7 +8,7 @@ import 'package:path/path.dart';
class ImageCollection with ChangeNotifier { class ImageCollection with ChangeNotifier {
final List<ImageEntry> _rawEntries; final List<ImageEntry> _rawEntries;
Map<dynamic, List<ImageEntry>> sections = {}; Map<dynamic, List<ImageEntry>> sections = Map.unmodifiable({});
GroupFactor groupFactor = GroupFactor.month; GroupFactor groupFactor = GroupFactor.month;
SortFactor sortFactor = SortFactor.date; SortFactor sortFactor = SortFactor.date;
List<String> sortedAlbums = List.unmodifiable(const Iterable.empty()); List<String> sortedAlbums = List.unmodifiable(const Iterable.empty());
@ -48,23 +48,22 @@ class ImageCollection with ChangeNotifier {
case SortFactor.date: case SortFactor.date:
switch (groupFactor) { switch (groupFactor) {
case GroupFactor.album: case GroupFactor.album:
sections = groupBy(_rawEntries, (entry) => entry.directory); sections = Map.unmodifiable(groupBy(_rawEntries, (entry) => entry.directory));
break; break;
case GroupFactor.month: case GroupFactor.month:
sections = groupBy(_rawEntries, (entry) => entry.monthTaken); sections = Map.unmodifiable(groupBy(_rawEntries, (entry) => entry.monthTaken));
break; break;
case GroupFactor.day: case GroupFactor.day:
sections = groupBy(_rawEntries, (entry) => entry.dayTaken); sections = Map.unmodifiable(groupBy(_rawEntries, (entry) => entry.dayTaken));
break; break;
} }
break; break;
case SortFactor.size: case SortFactor.size:
sections = Map.fromEntries([ sections = Map.unmodifiable(Map.fromEntries([
MapEntry('All', _rawEntries), MapEntry(null, _rawEntries),
]); ]));
break; break;
} }
debugPrint('$runtimeType updateSections notifyListeners');
notifyListeners(); notifyListeners();
} }

View file

@ -11,29 +11,23 @@ import 'package:provider/provider.dart';
class SectionSliver extends StatelessWidget { class SectionSliver extends StatelessWidget {
final ImageCollection collection; final ImageCollection collection;
final Map<dynamic, List<ImageEntry>> sections;
final dynamic sectionKey; final dynamic sectionKey;
static const columnCount = 4;
const SectionSliver({ const SectionSliver({
Key key, Key key,
@required this.collection, @required this.collection,
@required this.sections,
@required this.sectionKey, @required this.sectionKey,
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const columnCount = 4; final sections = collection.sections;
return SliverStickyHeader(
header: SectionHeader( final sliver = SliverGrid(
collection: collection,
sections: sections,
sectionKey: sectionKey,
),
sliver: SliverGrid(
delegate: SliverChildBuilderDelegate( delegate: SliverChildBuilderDelegate(
// TODO TLAD find out why thumbnails are rebuilt (with `initState`) when: // TODO TLAD find out why thumbnails are rebuilt (with `initState`)
// - config change (show/hide status bar)
(context, index) { (context, index) {
final sectionEntries = sections[sectionKey]; final sectionEntries = sections[sectionKey];
if (index >= sectionEntries.length) return null; if (index >= sectionEntries.length) return null;
@ -60,7 +54,15 @@ class SectionSliver extends StatelessWidget {
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: columnCount, crossAxisCount: columnCount,
), ),
);
return SliverStickyHeader(
header: SectionHeader(
collection: collection,
sections: sections,
sectionKey: sectionKey,
), ),
sliver: sliver,
overlapsContent: false, overlapsContent: false,
); );
} }

View file

@ -34,11 +34,7 @@ class ThumbnailCollection extends StatelessWidget {
slivers: [ slivers: [
if (appBar != null) appBar, if (appBar != null) appBar,
...sectionKeys.map((sectionKey) => SectionSliver( ...sectionKeys.map((sectionKey) => SectionSliver(
// need key to prevent section header mismatch
// but it should not be unique key, otherwise sections are rebuilt when changing page
key: ValueKey(sectionKey),
collection: collection, collection: collection,
sections: sections,
sectionKey: sectionKey, sectionKey: sectionKey,
)), )),
SliverToBoxAdapter( SliverToBoxAdapter(
@ -59,7 +55,7 @@ class ThumbnailCollection extends StatelessWidget {
return DraggableScrollbar.arrows( return DraggableScrollbar.arrows(
controller: _scrollController, controller: _scrollController,
padding: EdgeInsets.only( padding: EdgeInsets.only(
// top padding to adjust scroll thumb // padding to get scroll thumb below app bar, above nav bar
top: topPadding, top: topPadding,
bottom: mqViewInsetsBottom, bottom: mqViewInsetsBottom,
), ),