Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add error bottom sheet component for improved error handling

AmanRajSinghMourya3d291a14eae7
diff --git a/mobile/packages/legacy/lib/components/error_bottom_sheet.dart b/mobile/packages/legacy/lib/components/error_bottom_sheet.dart
new file mode 100644
index 0000000000..2162836449
--- /dev/null
+++ b/mobile/packages/legacy/lib/components/error_bottom_sheet.dart
@@ -0,0 +1,116 @@
+import "package:ente_legacy/components/gradient_button.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/theme/colors.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_ui/theme/text_style.dart";
+import "package:flutter/material.dart";
+
+/// Shows an error bottom sheet with the given title and message
+Future<void> showErrorBottomSheet(
+ BuildContext context, {
+ required String title,
+ required String message,
+}) {
+ return showModalBottomSheet<void>(
+ context: context,
+ isScrollControlled: true,
+ builder: (context) => ErrorBottomSheet(
+ title: title,
+ message: message,
+ ),
+ );
+}
+
+class ErrorBottomSheet extends StatelessWidget {
+ final String title;
+ final String message;
+
+ const ErrorBottomSheet({
+ required this.title,
+ required this.message,
+ 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(24),
+ topRight: Radius.circular(24),
+ ),
+ ),
+ child: SafeArea(
+ top: false,
+ child: Padding(
+ padding: const EdgeInsets.all(16),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ _buildHeader(context, colorScheme, textTheme),
+ const SizedBox(height: 20),
+ _buildContent(context, colorScheme, textTheme),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ Widget _buildHeader(
+ BuildContext context,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ title,
+ style: textTheme.largeBold,
+ ),
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Container(
+ padding: const EdgeInsets.all(8),
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ shape: BoxShape.circle,
+ ),
+ child: Icon(
+ Icons.close,
+ size: 20,
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ Widget _buildContent(
+ BuildContext context,
+ EnteColorScheme colorScheme,
+ EnteTextTheme textTheme,
+ ) {
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ message,
+ style: textTheme.small.copyWith(color: colorScheme.textMuted),
+ ),
+ const SizedBox(height: 20),
+ GradientButton(
+ text: context.strings.ok,
+ onTap: () => Navigator.of(context).pop(),
+ ),
+ ],
+ );
+ }
+}