Remove redundant container widget
This commit is contained in:
parent
c25ee04658
commit
c319a2e437
2 changed files with 47 additions and 109 deletions
|
@ -1,87 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/photo_repository.dart';
|
||||
import 'package:photos/ui/gallery.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/search_page.dart';
|
||||
import 'package:photos/utils/important_items_filter.dart';
|
||||
|
||||
// TODO: Remove redundant layer
|
||||
class GalleryContainer extends StatefulWidget {
|
||||
final Set<Photo> selectedPhotos;
|
||||
final Function(Set<Photo>) photoSelectionChangeCallback;
|
||||
|
||||
const GalleryContainer(
|
||||
this.selectedPhotos,
|
||||
this.photoSelectionChangeCallback, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_GalleryContainerState createState() => _GalleryContainerState();
|
||||
}
|
||||
|
||||
class _GalleryContainerState extends State<GalleryContainer> {
|
||||
static final importantItemsFilter = ImportantItemsFilter();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: <Widget>[_buildHero(context), _buildGallery()],
|
||||
);
|
||||
}
|
||||
|
||||
FutureBuilder<bool> _buildGallery() {
|
||||
return FutureBuilder<bool>(
|
||||
future: PhotoRepository.instance.loadPhotos(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Flexible(
|
||||
child: Gallery(
|
||||
getFilteredPhotos(PhotoRepository.instance.photos),
|
||||
widget.selectedPhotos,
|
||||
photoSelectionChangeCallback: widget.photoSelectionChangeCallback,
|
||||
),
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text("Error!");
|
||||
} else {
|
||||
return loadWidget;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Hero _buildHero(BuildContext context) {
|
||||
return Hero(
|
||||
child: TextField(
|
||||
readOnly: true,
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return SearchPage();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
hintText: 'Search "Paris"',
|
||||
contentPadding: const EdgeInsets.all(12.0),
|
||||
),
|
||||
),
|
||||
tag: "search");
|
||||
}
|
||||
|
||||
List<Photo> getFilteredPhotos(List<Photo> unfilteredPhotos) {
|
||||
final List<Photo> filteredPhotos = List<Photo>();
|
||||
for (Photo photo in unfilteredPhotos) {
|
||||
if (importantItemsFilter.shouldInclude(photo)) {
|
||||
filteredPhotos.add(photo);
|
||||
}
|
||||
}
|
||||
return filteredPhotos;
|
||||
}
|
||||
}
|
|
@ -9,8 +9,10 @@ import 'package:photos/events/local_photos_updated_event.dart';
|
|||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/photo_repository.dart';
|
||||
import 'package:photos/ui/album_list_widget.dart';
|
||||
import 'package:photos/ui/gallery.dart';
|
||||
import 'package:photos/ui/gallery_app_bar_widget.dart';
|
||||
import 'package:photos/ui/gallery_container_widget.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/utils/important_items_filter.dart';
|
||||
import 'package:photos/utils/logging_util.dart';
|
||||
import 'package:shake/shake.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
@ -25,6 +27,7 @@ class HomeWidget extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _HomeWidgetState extends State<HomeWidget> {
|
||||
static final importantItemsFilter = ImportantItemsFilter();
|
||||
final _logger = Logger("HomeWidgetState");
|
||||
ShakeDetector _detector;
|
||||
int _selectedNavBarItem = 0;
|
||||
|
@ -51,31 +54,37 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
appBar: GalleryAppBarWidget(
|
||||
widget.title,
|
||||
_selectedPhotos,
|
||||
onSelectionClear: () {
|
||||
setState(() {
|
||||
_selectedPhotos.clear();
|
||||
});
|
||||
},
|
||||
onSelectionClear: _clearSelectedPhotos,
|
||||
onPhotosDeleted: (_) {
|
||||
setState(() {
|
||||
_selectedPhotos.clear();
|
||||
});
|
||||
_clearSelectedPhotos();
|
||||
},
|
||||
),
|
||||
bottomNavigationBar: _buildBottomNavigationBar(),
|
||||
body: IndexedStack(
|
||||
children: <Widget>[
|
||||
GalleryContainer(
|
||||
_selectedPhotos,
|
||||
(Set<Photo> selectedPhotos) {
|
||||
setState(() {
|
||||
_selectedPhotos = selectedPhotos;
|
||||
});
|
||||
},
|
||||
),
|
||||
AlbumListWidget(PhotoRepository.instance.photos)
|
||||
],
|
||||
index: _selectedNavBarItem,
|
||||
body: FutureBuilder<bool>(
|
||||
future: PhotoRepository.instance.loadPhotos(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return IndexedStack(
|
||||
children: <Widget>[
|
||||
Gallery(
|
||||
_getFilteredPhotos(PhotoRepository.instance.photos),
|
||||
_selectedPhotos,
|
||||
photoSelectionChangeCallback: (Set<Photo> selectedPhotos) {
|
||||
setState(() {
|
||||
_selectedPhotos = selectedPhotos;
|
||||
});
|
||||
},
|
||||
),
|
||||
AlbumListWidget(PhotoRepository.instance.photos)
|
||||
],
|
||||
index: _selectedNavBarItem,
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text("Error!");
|
||||
} else {
|
||||
return loadWidget;
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -102,6 +111,22 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
List<Photo> _getFilteredPhotos(List<Photo> unfilteredPhotos) {
|
||||
final List<Photo> filteredPhotos = List<Photo>();
|
||||
for (Photo photo in unfilteredPhotos) {
|
||||
if (importantItemsFilter.shouldInclude(photo)) {
|
||||
filteredPhotos.add(photo);
|
||||
}
|
||||
}
|
||||
return filteredPhotos;
|
||||
}
|
||||
|
||||
void _clearSelectedPhotos() {
|
||||
setState(() {
|
||||
_selectedPhotos.clear();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_detector.stopListening();
|
||||
|
|
Loading…
Add table
Reference in a new issue