Remove unnecessary constructor parameter from DeviceFolderGalleryWidget
This commit is contained in:
parent
2f3951f124
commit
21a8fa8a41
3 changed files with 118 additions and 5 deletions
|
@ -5,16 +5,13 @@ import 'package:photos/favorite_photos_repository.dart';
|
|||
import 'package:photos/models/device_folder.dart';
|
||||
import 'package:photos/models/filters/favorite_items_filter.dart';
|
||||
import 'package:photos/models/filters/folder_name_filter.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
import 'package:photos/ui/device_folder_page.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/thumbnail_widget.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
class DeviceFolderGalleryWidget extends StatefulWidget {
|
||||
final List<Photo> photos;
|
||||
|
||||
const DeviceFolderGalleryWidget(this.photos, {Key key}) : super(key: key);
|
||||
const DeviceFolderGalleryWidget({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_DeviceFolderGalleryWidgetState createState() =>
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:photos/ui/device_folders_gallery_widget.dart';
|
|||
import 'package:photos/ui/gallery.dart';
|
||||
import 'package:photos/ui/gallery_app_bar_widget.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/remote_folder_gallery_widget.dart';
|
||||
import 'package:photos/utils/logging_util.dart';
|
||||
import 'package:shake/shake.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
@ -74,7 +75,8 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
});
|
||||
},
|
||||
),
|
||||
DeviceFolderGalleryWidget(PhotoRepository.instance.photos)
|
||||
DeviceFolderGalleryWidget(),
|
||||
RemoteFolderGalleryWidget(),
|
||||
],
|
||||
index: _selectedNavBarItem,
|
||||
);
|
||||
|
@ -99,6 +101,10 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
icon: Icon(Icons.photo_library),
|
||||
title: Text('Gallery'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.folder_shared),
|
||||
title: Text('Shared'),
|
||||
),
|
||||
],
|
||||
currentIndex: _selectedNavBarItem,
|
||||
selectedItemColor: Colors.yellow[800],
|
||||
|
|
110
lib/ui/remote_folder_gallery_widget.dart
Normal file
110
lib/ui/remote_folder_gallery_widget.dart
Normal file
|
@ -0,0 +1,110 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:photos/db/photo_db.dart';
|
||||
import 'package:photos/favorite_photos_repository.dart';
|
||||
import 'package:photos/models/device_folder.dart';
|
||||
import 'package:photos/models/filters/favorite_items_filter.dart';
|
||||
import 'package:photos/models/filters/folder_name_filter.dart';
|
||||
import 'package:photos/ui/device_folder_page.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/thumbnail_widget.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
class RemoteFolderGalleryWidget extends StatefulWidget {
|
||||
const RemoteFolderGalleryWidget({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_RemoteFolderGalleryWidgetState createState() =>
|
||||
_RemoteFolderGalleryWidgetState();
|
||||
}
|
||||
|
||||
class _RemoteFolderGalleryWidgetState extends State<RemoteFolderGalleryWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: _getDeviceFolders(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return _getDeviceFolderGalleryWidget(snapshot.data);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
} else {
|
||||
return loadWidget;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getDeviceFolderGalleryWidget(List<DeviceFolder> folders) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 24),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
physics: ScrollPhysics(), // to disable GridView's scrolling
|
||||
itemBuilder: (context, index) {
|
||||
return _buildFolder(context, folders[index]);
|
||||
},
|
||||
itemCount: folders.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<DeviceFolder>> _getDeviceFolders() async {
|
||||
final paths = await PhotoDB.instance.getDistinctPaths();
|
||||
final folders = List<DeviceFolder>();
|
||||
for (final path in paths) {
|
||||
final photo = await PhotoDB.instance.getLatestPhotoInPath(path);
|
||||
final folderName = p.basename(path);
|
||||
folders
|
||||
.add(DeviceFolder(folderName, photo, FolderNameFilter(folderName)));
|
||||
}
|
||||
folders.sort((first, second) {
|
||||
return second.thumbnailPhoto.createTimestamp
|
||||
.compareTo(first.thumbnailPhoto.createTimestamp);
|
||||
});
|
||||
if (FavoritePhotosRepository.instance.hasFavorites()) {
|
||||
final photo = await PhotoDB.instance.getLatestPhotoAmongGeneratedIds(
|
||||
FavoritePhotosRepository.instance.getLiked().toList());
|
||||
folders.insert(
|
||||
0, DeviceFolder("Favorites", photo, FavoriteItemsFilter()));
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
|
||||
Widget _buildFolder(BuildContext context, DeviceFolder folder) {
|
||||
return GestureDetector(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: ThumbnailWidget(folder.thumbnailPhoto),
|
||||
height: 150,
|
||||
width: 150,
|
||||
),
|
||||
Padding(padding: EdgeInsets.all(2)),
|
||||
Expanded(
|
||||
child: Text(
|
||||
folder.name,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
final page = DeviceFolderPage(folder);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return page;
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue