Add a button to create an album
This commit is contained in:
parent
22f670ccd4
commit
36ab7edb7c
4 changed files with 46 additions and 6 deletions
7
lib/events/tab_changed_event.dart
Normal file
7
lib/events/tab_changed_event.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
import 'package:sentry/sentry.dart';
|
||||
|
||||
class TabChangedEvent extends Event {
|
||||
final selectedIndex;
|
||||
|
||||
TabChangedEvent(this.selectedIndex);
|
||||
}
|
|
@ -1,10 +1,13 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:event_bus/event_bus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/events/local_photos_updated_event.dart';
|
||||
import 'package:photos/events/tab_changed_event.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/repositories/file_repository.dart';
|
||||
|
@ -15,6 +18,7 @@ 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;
|
||||
import 'package:photos/utils/toast_util.dart';
|
||||
|
||||
class CollectionsGalleryWidget extends StatefulWidget {
|
||||
const CollectionsGalleryWidget({Key key}) : super(key: key);
|
||||
|
@ -80,9 +84,9 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget> {
|
|||
padding: EdgeInsets.only(bottom: 12),
|
||||
physics: ScrollPhysics(), // to disable GridView's scrolling
|
||||
itemBuilder: (context, index) {
|
||||
return _buildCollection(context, items.collections[index]);
|
||||
return _buildCollection(context, items.collections, index);
|
||||
},
|
||||
itemCount: items.collections.length,
|
||||
itemCount: items.collections.length + 1, // To include the + button
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
),
|
||||
|
@ -165,7 +169,27 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildCollection(BuildContext context, CollectionWithThumbnail c) {
|
||||
Widget _buildCollection(BuildContext context,
|
||||
List<CollectionWithThumbnail> collections, int index) {
|
||||
if (index == collections.length) {
|
||||
return Container(
|
||||
height: 150,
|
||||
width: 150,
|
||||
margin: EdgeInsets.fromLTRB(0, 0, 12, 28),
|
||||
child: OutlineButton(
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
),
|
||||
onPressed: () async {
|
||||
await showToast(
|
||||
"Long press to select photos and click + to create an album.",
|
||||
toastLength: Toast.LENGTH_LONG);
|
||||
Bus.instance.fire(TabChangedEvent(0));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
final c = collections[index];
|
||||
return GestureDetector(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart';
|
|||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/events/local_photos_updated_event.dart';
|
||||
import 'package:photos/events/tab_changed_event.dart';
|
||||
import 'package:photos/models/filters/important_items_filter.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/repositories/file_repository.dart';
|
||||
|
@ -47,6 +48,7 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
int _selectedNavBarItem = 0;
|
||||
StreamSubscription<LocalPhotosUpdatedEvent>
|
||||
_localPhotosUpdatedEventSubscription;
|
||||
StreamSubscription<TabChangedEvent> _tabChangedEventSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -60,6 +62,12 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
|
||||
setState(() {});
|
||||
});
|
||||
_tabChangedEventSubscription =
|
||||
Bus.instance.on<TabChangedEvent>().listen((event) {
|
||||
setState(() {
|
||||
_selectedNavBarItem = event.selectedIndex;
|
||||
});
|
||||
});
|
||||
_initDeepLinks();
|
||||
super.initState();
|
||||
}
|
||||
|
@ -211,6 +219,7 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
void dispose() {
|
||||
_detector.stopListening();
|
||||
_localPhotosUpdatedEventSubscription.cancel();
|
||||
_tabChangedEventSubscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
void showToast(String message, {toastLength: Toast.LENGTH_SHORT}) {
|
||||
Fluttertoast.showToast(
|
||||
Future<void> showToast(String message, {toastLength: Toast.LENGTH_SHORT}) {
|
||||
return Fluttertoast.showToast(
|
||||
msg: message,
|
||||
toastLength: toastLength,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
timeInSecForIosWeb: 1,
|
||||
backgroundColor: Colors.grey[850],
|
||||
backgroundColor: Colors.grey[800],
|
||||
textColor: Colors.white,
|
||||
fontSize: 16.0);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue