Skip to content

armgit / ente

Public Imported from GitHub
0

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

add bottom sheet components

AmanRajSinghMouryad5df82aa3954
diff --git a/mobile/apps/photos/lib/ui/components/alert_bottom_sheet.dart b/mobile/apps/photos/lib/ui/components/alert_bottom_sheet.dart
new file mode 100644
index 0000000000..1488cdca4d
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/components/alert_bottom_sheet.dart
@@ -0,0 +1,118 @@
+import "package:flutter/material.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/components/base_bottom_sheet.dart";
+
+Future<T?> showAlertBottomSheet<T>(
+ BuildContext context, {
+ required String title,
+ required String message,
+ String? assetPath,
+ List<Widget>? buttons,
+ bool isDismissible = true,
+ bool showCloseButton = true,
+ VoidCallback? onClose,
+}) {
+ return showModalBottomSheet<T>(
+ context: context,
+ isScrollControlled: true,
+ isDismissible: isDismissible,
+ enableDrag: isDismissible,
+ backgroundColor: Colors.transparent,
+ builder: (context) => AlertBottomSheet<T>(
+ title: title,
+ message: message,
+ assetPath: assetPath,
+ buttons: buttons,
+ showCloseButton: showCloseButton,
+ onClose: onClose,
+ ),
+ );
+}
+
+class AlertBottomSheet<T> extends StatelessWidget {
+ final String title;
+ final String message;
+ final String? assetPath;
+ final List<Widget>? buttons;
+ final bool showCloseButton;
+ final VoidCallback? onClose;
+
+ const AlertBottomSheet({
+ required this.title,
+ required this.message,
+ this.assetPath,
+ this.buttons,
+ this.showCloseButton = true,
+ this.onClose,
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Container(
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated2,
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(20),
+ topRight: Radius.circular(20),
+ ),
+ ),
+ child: SafeArea(
+ top: false,
+ child: Padding(
+ padding: const EdgeInsets.all(16),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ if (showCloseButton)
+ Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ BottomSheetCloseButton(onTap: onClose),
+ ],
+ ),
+ SizedBox(height: showCloseButton ? 12 : 24),
+ if (assetPath != null) ...[
+ Center(child: Image.asset(assetPath!)),
+ const SizedBox(height: 20),
+ ],
+ Text(
+ title,
+ style: textTheme.h3Bold,
+ textAlign: TextAlign.center,
+ ),
+ const SizedBox(height: 12),
+ Text(
+ message,
+ style: textTheme.body.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ textAlign: TextAlign.center,
+ ),
+ ..._buildButtonsSection(),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ List<Widget> _buildButtonsSection() {
+ if (buttons == null || buttons!.isEmpty) return [];
+
+ return [
+ const SizedBox(height: 20),
+ ListView.separated(
+ shrinkWrap: true,
+ physics: const NeverScrollableScrollPhysics(),
+ itemCount: buttons!.length,
+ separatorBuilder: (_, __) => const SizedBox(height: 12),
+ itemBuilder: (_, index) => buttons![index],
+ ),
+ ];
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/components/base_bottom_sheet.dart b/mobile/apps/photos/lib/ui/components/base_bottom_sheet.dart
index a29681d40b..59b422c494 100644
--- a/mobile/apps/photos/lib/ui/components/base_bottom_sheet.dart
+++ b/mobile/apps/photos/lib/ui/components/base_bottom_sheet.dart
@@ -1,4 +1,5 @@
import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
import "package:photos/theme/ente_theme.dart";
Future<T?> showBaseBottomSheet<T>(
@@ -89,26 +90,12 @@ class BaseBottomSheet extends StatelessWidget {
children: [
Text(title, style: textTheme.largeBold),
if (showCloseButton)
- GestureDetector(
- onTap: onClose ?? () => Navigator.of(context).pop(),
- child: Container(
- padding: const EdgeInsets.all(8),
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: colorScheme.fillFaint,
- ),
- child: Icon(
- Icons.close,
- size: 24,
- color: colorScheme.textBase,
- ),
- ),
- )
+ BottomSheetCloseButton(onTap: onClose)
else
const SizedBox.shrink(),
],
),
- SizedBox(height: headerSpacing),
+ if (headerSpacing > 0) SizedBox(height: headerSpacing),
child,
],
),
@@ -118,3 +105,30 @@ class BaseBottomSheet extends StatelessWidget {
);
}
}
+
+class BottomSheetCloseButton extends StatelessWidget {
+ final VoidCallback? onTap;
+
+ const BottomSheetCloseButton({super.key, this.onTap});
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+
+ return GestureDetector(
+ onTap: onTap ?? () => Navigator.of(context).pop(),
+ child: Container(
+ padding: const EdgeInsets.all(8),
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: colorScheme.fillFaint,
+ ),
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: 24,
+ color: colorScheme.textBase,
+ ),
+ ),
+ );
+ }
+}