Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][locker] Simplify add to collection sheet

aman-pilot57d5f2b9a0d3
diff --git a/mobile/apps/locker/lib/ui/components/add_to_collection_sheet.dart b/mobile/apps/locker/lib/ui/components/add_to_collection_sheet.dart
index 99db4b6ffc..f026239c3a 100644
--- a/mobile/apps/locker/lib/ui/components/add_to_collection_sheet.dart
+++ b/mobile/apps/locker/lib/ui/components/add_to_collection_sheet.dart
@@ -1,6 +1,4 @@
import "package:ente_components/ente_components.dart";
-import "package:ente_ui/components/base_bottom_sheet.dart";
-import "package:ente_ui/utils/toast_util.dart";
import "package:flutter/material.dart";
import "package:locker/l10n/l10n.dart";
import "package:locker/services/collections/models/collection.dart";
@@ -15,13 +13,8 @@ class AddToCollectionSheetResult {
class AddToCollectionSheet extends StatefulWidget {
final List<Collection> collections;
- final BuildContext snackBarContext;
- const AddToCollectionSheet({
- super.key,
- required this.collections,
- required this.snackBarContext,
- });
+ const AddToCollectionSheet({super.key, required this.collections});
@override
State<AddToCollectionSheet> createState() => _AddToCollectionSheetState();
@@ -31,6 +24,8 @@ class _AddToCollectionSheetState extends State<AddToCollectionSheet> {
final Set<int> _selectedCollectionIds = <int>{};
List<Collection> _availableCollections = [];
+ bool get _canSave => _selectedCollectionIds.isNotEmpty;
+
@override
void initState() {
super.initState();
@@ -57,15 +52,6 @@ class _AddToCollectionSheetState extends State<AddToCollectionSheet> {
final selectedCollections = _availableCollections
.where((c) => _selectedCollectionIds.contains(c.id))
.toList();
-
- if (selectedCollections.isEmpty) {
- showToast(
- widget.snackBarContext,
- widget.snackBarContext.l10n.pleaseSelectAtLeastOneCollection,
- );
- return;
- }
-
Navigator.of(
context,
).pop(AddToCollectionSheetResult(selectedCollections: selectedCollections));
@@ -73,23 +59,19 @@ class _AddToCollectionSheetState extends State<AddToCollectionSheet> {
@override
Widget build(BuildContext context) {
- return Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- CollectionSelectionWidget(
- collections: _availableCollections,
- selectedCollectionIds: _selectedCollectionIds,
- onToggleCollection: _toggleCollection,
- onCollectionsUpdated: _onCollectionsUpdated,
- title: context.l10n.collections,
- ),
- const SizedBox(height: 28),
+ return BottomSheetComponent(
+ title: context.l10n.addToCollection,
+ content: CollectionSelectionWidget(
+ collections: _availableCollections,
+ selectedCollectionIds: _selectedCollectionIds,
+ onToggleCollection: _toggleCollection,
+ onCollectionsUpdated: _onCollectionsUpdated,
+ title: context.l10n.collections,
+ ),
+ actions: [
ButtonComponent(
label: context.l10n.save,
- onTap: () async {
- await _onSave();
- },
+ onTap: _canSave ? _onSave : null,
),
],
);
@@ -99,16 +81,9 @@ class _AddToCollectionSheetState extends State<AddToCollectionSheet> {
Future<AddToCollectionSheetResult?> showAddToCollectionSheet(
BuildContext context, {
required List<Collection> collections,
- BuildContext? snackBarContext,
}) async {
- final messengerContext = snackBarContext ?? context;
- return showBaseBottomSheet<AddToCollectionSheetResult>(
- context,
- title: context.l10n.addToCollection,
- headerSpacing: 20,
- child: AddToCollectionSheet(
- collections: collections,
- snackBarContext: messengerContext,
- ),
+ return showBottomSheetComponent<AddToCollectionSheetResult>(
+ context: context,
+ builder: (_) => AddToCollectionSheet(collections: collections),
);
}