diff --git a/lib/widgets/album/all_collection_page.dart b/lib/widgets/album/all_collection_page.dart index daa421853..a44184ced 100644 --- a/lib/widgets/album/all_collection_page.dart +++ b/lib/widgets/album/all_collection_page.dart @@ -7,6 +7,7 @@ import 'package:aves/widgets/debug_page.dart'; import 'package:aves/widgets/stats.dart'; import 'package:flutter/material.dart'; import 'package:outline_material_icons/outline_material_icons.dart'; +import 'package:pedantic/pedantic.dart'; import 'package:provider/provider.dart'; class AllCollectionPage extends StatelessWidget { @@ -90,13 +91,15 @@ class _AllCollectionAppBar extends SliverAppBar { ]; } - static void _onActionSelected(BuildContext context, CollectionLens collection, AlbumAction action) { + static void _onActionSelected(BuildContext context, CollectionLens collection, AlbumAction action) async { + // wait for the popup menu to hide before proceeding with the action + await Future.delayed(const Duration(milliseconds: 300)); switch (action) { case AlbumAction.debug: - _goToDebug(context, collection); + unawaited(_goToDebug(context, collection)); break; case AlbumAction.stats: - _goToStats(context, collection); + unawaited(_goToStats(context, collection)); break; case AlbumAction.groupByAlbum: settings.collectionGroupFactor = GroupFactor.album; diff --git a/lib/widgets/album/collection_section.dart b/lib/widgets/album/collection_section.dart index d235f2742..ac7969dbc 100644 --- a/lib/widgets/album/collection_section.dart +++ b/lib/widgets/album/collection_section.dart @@ -25,35 +25,24 @@ class SectionSliver extends StatelessWidget { @override Widget build(BuildContext context) { final sections = collection.sections; + final sectionEntries = sections[sectionKey]; + final childCount = sectionEntries.length; final sliver = SliverGrid( delegate: SliverChildBuilderDelegate( - // TODO TLAD find out why thumbnails are rebuilt (with `initState`) - (context, index) { - final sectionEntries = sections[sectionKey]; - if (index >= sectionEntries.length) return null; - final entry = sectionEntries[index]; - return GestureDetector( - key: ValueKey(entry.uri), - onTap: () => _showFullscreen(context, entry), - child: Selector( - selector: (c, mq) => mq.size.width, - builder: (c, mqWidth, child) { - return MetaData( - metaData: ThumbnailMetadata(index, entry), - child: Thumbnail( - entry: entry, - extent: mqWidth / columnCount, - heroTag: collection.heroTag(entry), - ), - ); - }, - ), - ); - }, - childCount: sections[sectionKey].length, + // TODO TLAD thumbnails at the beginning of each sections are built even though they are offscreen + // because of `RenderSliverMultiBoxAdaptor.addInitialChild` + // called by `RenderSliverGrid.performLayout` (line 547) + (context, index) => index < childCount + ? GridThumbnail( + collection: collection, + index: index, + entry: sectionEntries[index], + columnCount: columnCount, + ) + : null, + childCount: childCount, addAutomaticKeepAlives: false, - addRepaintBoundaries: true, ), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: columnCount, @@ -70,12 +59,50 @@ class SectionSliver extends StatelessWidget { overlapsContent: false, ); } +} - void _showFullscreen(BuildContext context, ImageEntry entry) { +class GridThumbnail extends StatelessWidget { + final CollectionLens collection; + final int index; + final ImageEntry entry; + final int columnCount; + final GestureTapCallback onTap; + + const GridThumbnail({ + Key key, + this.collection, + this.index, + this.entry, + this.columnCount, + this.onTap, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector( + key: ValueKey(entry.uri), + onTap: () => _showFullscreen(context), + child: Selector( + selector: (c, mq) => mq.size.width, + builder: (c, mqWidth, child) { + return MetaData( + metaData: ThumbnailMetadata(index, entry), + child: Thumbnail( + entry: entry, + extent: mqWidth / columnCount, + heroTag: collection.heroTag(entry), + ), + ); + }, + ), + ); + } + + void _showFullscreen(BuildContext context) { Navigator.push( context, TransparentMaterialPageRoute( - pageBuilder: (context, _, __) => MultiFullscreenPage( + pageBuilder: (c, a, sa) => MultiFullscreenPage( collection: collection, initialEntry: entry, ), diff --git a/pubspec.lock b/pubspec.lock index 3d162fcb6..1a80db4dc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -129,13 +129,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.6" - flutter_staggered_grid_view: - dependency: "direct main" - description: - name: flutter_staggered_grid_view - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.0" flutter_sticky_header: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index a885d5142..d4eaca27f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,7 +29,6 @@ dependencies: url: https://github.com/AndreHaueisen/flushbar.git ref: 13c55a8 flutter_native_timezone: - flutter_staggered_grid_view: flutter_sticky_header: git: url: git://github.com/deckerst/flutter_sticky_header.git