diff --git a/lib/ui/album_widget.dart b/lib/ui/album_widget.dart index 42b863244..910e12121 100644 --- a/lib/ui/album_widget.dart +++ b/lib/ui/album_widget.dart @@ -35,11 +35,13 @@ class _AlbumPageState extends State { Logger().i("Deleting " + index.toString()); widget.album.photos.removeAt(index); } + _selectedPhotos.clear(); }); }, ), body: Gallery( widget.album.photos, + _selectedPhotos, photoSelectionChangeCallback: (Set selectedPhotos) { setState(() { _selectedPhotos = selectedPhotos; diff --git a/lib/ui/gallery.dart b/lib/ui/gallery.dart index 8ada1b005..449ecd934 100644 --- a/lib/ui/gallery.dart +++ b/lib/ui/gallery.dart @@ -16,9 +16,11 @@ import 'package:myapp/core/constants.dart'; class Gallery extends StatefulWidget { final List photos; + final Set selectedPhotos; final Function(Set) photoSelectionChangeCallback; - Gallery(this.photos, {this.photoSelectionChangeCallback}); + Gallery(this.photos, this.selectedPhotos, + {this.photoSelectionChangeCallback}); @override _GalleryState createState() { @@ -29,15 +31,14 @@ class Gallery extends StatefulWidget { class _GalleryState extends State { final ScrollController _scrollController = ScrollController(); final List> _collatedPhotos = List>(); - final Set _selectedPhotos = HashSet(); + Set _selectedPhotos = HashSet(); PhotoLoader get photoLoader => Provider.of(context); - bool _shouldSelectOnTap = false; List _photos; @override Widget build(BuildContext context) { _photos = widget.photos; - Logger().i("Building with " + _photos.length.toString()); + _selectedPhotos = widget.selectedPhotos; _collatePhotos(); return ListView.builder( @@ -87,7 +88,7 @@ class _GalleryState extends State { Widget _buildPhoto(BuildContext context, Photo photo) { return GestureDetector( onTap: () { - if (_shouldSelectOnTap) { + if (_selectedPhotos.isNotEmpty) { _selectPhoto(photo); } else { routeToDetailPage(photo, context); @@ -116,11 +117,6 @@ class _GalleryState extends State { } else { _selectedPhotos.add(photo); } - if (_selectedPhotos.isNotEmpty) { - _shouldSelectOnTap = true; - } else { - _shouldSelectOnTap = false; - } widget.photoSelectionChangeCallback(_selectedPhotos); }); } diff --git a/lib/ui/gallery_app_bar_widget.dart b/lib/ui/gallery_app_bar_widget.dart index b91e7085b..701aa79ea 100644 --- a/lib/ui/gallery_app_bar_widget.dart +++ b/lib/ui/gallery_app_bar_widget.dart @@ -4,7 +4,6 @@ import 'package:myapp/db/db_helper.dart'; import 'package:myapp/models/photo.dart'; import 'package:myapp/photo_loader.dart'; import 'package:photo_manager/photo_manager.dart'; -import 'package:provider/provider.dart'; import 'package:myapp/utils/share_util.dart'; class GalleryAppBarWidget extends StatefulWidget diff --git a/lib/ui/gallery_container_widget.dart b/lib/ui/gallery_container_widget.dart index 93ec1f548..a4ea3745a 100644 --- a/lib/ui/gallery_container_widget.dart +++ b/lib/ui/gallery_container_widget.dart @@ -11,11 +11,13 @@ import 'package:provider/provider.dart'; // TODO: Remove redundant layer class GalleryContainer extends StatefulWidget { + final Set selectedPhotos; final Function(Set) photoSelectionChangeCallback; - const GalleryContainer({ + const GalleryContainer( + this.selectedPhotos, + this.photoSelectionChangeCallback, { Key key, - this.photoSelectionChangeCallback, }) : super(key: key); @override @@ -44,6 +46,7 @@ class _GalleryContainerState extends State { builder: (_, __) { return Gallery( getFilteredPhotos(photoLoader.photos), + widget.selectedPhotos, photoSelectionChangeCallback: widget.photoSelectionChangeCallback, ); diff --git a/lib/ui/home_widget.dart b/lib/ui/home_widget.dart index d3135b41b..77604a2c3 100644 --- a/lib/ui/home_widget.dart +++ b/lib/ui/home_widget.dart @@ -1,3 +1,5 @@ +import 'dart:collection'; + import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; @@ -21,7 +23,7 @@ class HomeWidget extends StatefulWidget { class _HomeWidgetState extends State { PhotoLoader get photoLoader => Provider.of(context); int _selectedNavBarItem = 0; - Set _selectedPhotos = Set(); + Set _selectedPhotos = HashSet(); @override Widget build(BuildContext context) { @@ -34,12 +36,18 @@ class _HomeWidgetState extends State { _selectedPhotos.clear(); }); }, + onPhotosDeleted: (_) { + setState(() { + _selectedPhotos.clear(); + }); + }, ), bottomNavigationBar: _buildBottomNavigationBar(), body: IndexedStack( children: [ GalleryContainer( - photoSelectionChangeCallback: (Set selectedPhotos) { + _selectedPhotos, + (Set selectedPhotos) { setState(() { _selectedPhotos = selectedPhotos; });