|
@@ -1,27 +1,19 @@
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
-import 'package:logger/logger.dart';
|
|
|
|
import 'package:myapp/models/photo.dart';
|
|
import 'package:myapp/models/photo.dart';
|
|
|
|
+import 'package:myapp/photo_loader.dart';
|
|
import 'package:myapp/ui/change_notifier_builder.dart';
|
|
import 'package:myapp/ui/change_notifier_builder.dart';
|
|
|
|
+import 'package:myapp/ui/gallery.dart';
|
|
|
|
+import 'package:myapp/ui/loading_widget.dart';
|
|
import 'package:myapp/ui/search_page.dart';
|
|
import 'package:myapp/ui/search_page.dart';
|
|
import 'package:myapp/utils/important_items_filter.dart';
|
|
import 'package:myapp/utils/important_items_filter.dart';
|
|
-import 'package:myapp/utils/gallery_items_filter.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
-import '../photo_loader.dart';
|
|
|
|
-import 'gallery.dart';
|
|
|
|
-import 'loading_widget.dart';
|
|
|
|
-
|
|
|
|
// TODO: Remove redundant layer
|
|
// TODO: Remove redundant layer
|
|
class GalleryContainer extends StatefulWidget {
|
|
class GalleryContainer extends StatefulWidget {
|
|
- final GalleryType type;
|
|
|
|
final Function(Set<Photo>) photoSelectionChangeCallback;
|
|
final Function(Set<Photo>) photoSelectionChangeCallback;
|
|
|
|
|
|
- static final importantItemsFilter = ImportantItemsFilter();
|
|
|
|
- static final galleryItemsFilter = GalleryItemsFilter();
|
|
|
|
-
|
|
|
|
- const GalleryContainer(
|
|
|
|
- this.type, {
|
|
|
|
|
|
+ const GalleryContainer({
|
|
Key key,
|
|
Key key,
|
|
this.photoSelectionChangeCallback,
|
|
this.photoSelectionChangeCallback,
|
|
}) : super(key: key);
|
|
}) : super(key: key);
|
|
@@ -31,76 +23,69 @@ class GalleryContainer extends StatefulWidget {
|
|
}
|
|
}
|
|
|
|
|
|
class _GalleryContainerState extends State<GalleryContainer> {
|
|
class _GalleryContainerState extends State<GalleryContainer> {
|
|
|
|
+ static final importantItemsFilter = ImportantItemsFilter();
|
|
PhotoLoader get photoLoader => Provider.of<PhotoLoader>(context);
|
|
PhotoLoader get photoLoader => Provider.of<PhotoLoader>(context);
|
|
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
return Column(
|
|
- children: <Widget>[
|
|
|
|
- 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"),
|
|
|
|
- FutureBuilder<bool>(
|
|
|
|
- future: photoLoader.loadPhotos(),
|
|
|
|
- builder: (context, snapshot) {
|
|
|
|
- if (snapshot.hasData) {
|
|
|
|
- return ChangeNotifierBuilder(
|
|
|
|
|
|
+ children: <Widget>[_buildHero(context), _buildGallery()],
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FutureBuilder<bool> _buildGallery() {
|
|
|
|
+ return FutureBuilder<bool>(
|
|
|
|
+ future: photoLoader.loadPhotos(),
|
|
|
|
+ builder: (context, snapshot) {
|
|
|
|
+ if (snapshot.hasData) {
|
|
|
|
+ return Flexible(
|
|
|
|
+ child: ChangeNotifierBuilder(
|
|
value: photoLoader,
|
|
value: photoLoader,
|
|
builder: (_, __) {
|
|
builder: (_, __) {
|
|
- return Flexible(child: _getGallery(photoLoader.photos));
|
|
|
|
- });
|
|
|
|
- } else if (snapshot.hasError) {
|
|
|
|
- return Text("Error!");
|
|
|
|
- } else {
|
|
|
|
- return loadWidget;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- )
|
|
|
|
- ],
|
|
|
|
|
|
+ return Gallery(
|
|
|
|
+ getFilteredPhotos(photoLoader.photos),
|
|
|
|
+ photoSelectionChangeCallback:
|
|
|
|
+ widget.photoSelectionChangeCallback,
|
|
|
|
+ );
|
|
|
|
+ }));
|
|
|
|
+ } else if (snapshot.hasError) {
|
|
|
|
+ return Text("Error!");
|
|
|
|
+ } else {
|
|
|
|
+ return loadWidget;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Gallery _getGallery(List<Photo> photos) {
|
|
|
|
- return widget.type == GalleryType.important_photos
|
|
|
|
- ? Gallery(
|
|
|
|
- getFilteredPhotos(photos, GalleryContainer.importantItemsFilter),
|
|
|
|
- photoSelectionChangeCallback: widget.photoSelectionChangeCallback,
|
|
|
|
- )
|
|
|
|
- : Gallery(
|
|
|
|
- getFilteredPhotos(photos, GalleryContainer.galleryItemsFilter),
|
|
|
|
- photoSelectionChangeCallback: widget.photoSelectionChangeCallback,
|
|
|
|
- );
|
|
|
|
|
|
+ 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, GalleryItemsFilter filter) {
|
|
|
|
|
|
+ List<Photo> getFilteredPhotos(List<Photo> unfilteredPhotos) {
|
|
final List<Photo> filteredPhotos = List<Photo>();
|
|
final List<Photo> filteredPhotos = List<Photo>();
|
|
for (Photo photo in unfilteredPhotos) {
|
|
for (Photo photo in unfilteredPhotos) {
|
|
- if (filter.shouldInclude(photo)) {
|
|
|
|
|
|
+ if (importantItemsFilter.shouldInclude(photo)) {
|
|
filteredPhotos.add(photo);
|
|
filteredPhotos.add(photo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return filteredPhotos;
|
|
return filteredPhotos;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-enum GalleryType {
|
|
|
|
- important_photos,
|
|
|
|
- all_photos,
|
|
|
|
-}
|
|
|