Fix bug related to app bar on deletion
This commit is contained in:
parent
46f0e7905f
commit
25e68526a4
5 changed files with 23 additions and 15 deletions
|
@ -35,11 +35,13 @@ class _AlbumPageState extends State<AlbumPage> {
|
|||
Logger().i("Deleting " + index.toString());
|
||||
widget.album.photos.removeAt(index);
|
||||
}
|
||||
_selectedPhotos.clear();
|
||||
});
|
||||
},
|
||||
),
|
||||
body: Gallery(
|
||||
widget.album.photos,
|
||||
_selectedPhotos,
|
||||
photoSelectionChangeCallback: (Set<Photo> selectedPhotos) {
|
||||
setState(() {
|
||||
_selectedPhotos = selectedPhotos;
|
||||
|
|
|
@ -16,9 +16,11 @@ import 'package:myapp/core/constants.dart';
|
|||
|
||||
class Gallery extends StatefulWidget {
|
||||
final List<Photo> photos;
|
||||
final Set<Photo> selectedPhotos;
|
||||
final Function(Set<Photo>) 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<Gallery> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
final List<List<Photo>> _collatedPhotos = List<List<Photo>>();
|
||||
final Set<Photo> _selectedPhotos = HashSet<Photo>();
|
||||
Set<Photo> _selectedPhotos = HashSet<Photo>();
|
||||
PhotoLoader get photoLoader => Provider.of<PhotoLoader>(context);
|
||||
bool _shouldSelectOnTap = false;
|
||||
List<Photo> _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<Gallery> {
|
|||
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<Gallery> {
|
|||
} else {
|
||||
_selectedPhotos.add(photo);
|
||||
}
|
||||
if (_selectedPhotos.isNotEmpty) {
|
||||
_shouldSelectOnTap = true;
|
||||
} else {
|
||||
_shouldSelectOnTap = false;
|
||||
}
|
||||
widget.photoSelectionChangeCallback(_selectedPhotos);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,11 +11,13 @@ import 'package:provider/provider.dart';
|
|||
|
||||
// TODO: Remove redundant layer
|
||||
class GalleryContainer extends StatefulWidget {
|
||||
final Set<Photo> selectedPhotos;
|
||||
final Function(Set<Photo>) 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<GalleryContainer> {
|
|||
builder: (_, __) {
|
||||
return Gallery(
|
||||
getFilteredPhotos(photoLoader.photos),
|
||||
widget.selectedPhotos,
|
||||
photoSelectionChangeCallback:
|
||||
widget.photoSelectionChangeCallback,
|
||||
);
|
||||
|
|
|
@ -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<HomeWidget> {
|
||||
PhotoLoader get photoLoader => Provider.of<PhotoLoader>(context);
|
||||
int _selectedNavBarItem = 0;
|
||||
Set<Photo> _selectedPhotos = Set<Photo>();
|
||||
Set<Photo> _selectedPhotos = HashSet<Photo>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -34,12 +36,18 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
_selectedPhotos.clear();
|
||||
});
|
||||
},
|
||||
onPhotosDeleted: (_) {
|
||||
setState(() {
|
||||
_selectedPhotos.clear();
|
||||
});
|
||||
},
|
||||
),
|
||||
bottomNavigationBar: _buildBottomNavigationBar(),
|
||||
body: IndexedStack(
|
||||
children: <Widget>[
|
||||
GalleryContainer(
|
||||
photoSelectionChangeCallback: (Set<Photo> selectedPhotos) {
|
||||
_selectedPhotos,
|
||||
(Set<Photo> selectedPhotos) {
|
||||
setState(() {
|
||||
_selectedPhotos = selectedPhotos;
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue