Explorar el Código

Refactor notification widget

Neeraj Gupta hace 2 años
padre
commit
35654a716c

+ 0 - 71
lib/ui/components/notification_warning_widget.dart

@@ -1,71 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:photos/ente_theme_data.dart';
-import 'package:photos/theme/colors.dart';
-import 'package:photos/theme/text_style.dart';
-import 'package:photos/ui/components/icon_button_widget.dart';
-
-class NotificationWarningWidget extends StatelessWidget {
-  final IconData warningIcon;
-  final IconData actionIcon;
-  final String text;
-  final GestureTapCallback onTap;
-
-  const NotificationWarningWidget({
-    Key? key,
-    required this.warningIcon,
-    required this.actionIcon,
-    required this.text,
-    required this.onTap,
-  }) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    return Center(
-      child: GestureDetector(
-        onTap: onTap,
-        child: Padding(
-          padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12),
-          child: Container(
-            decoration: BoxDecoration(
-              borderRadius: const BorderRadius.all(
-                Radius.circular(8),
-              ),
-              boxShadow: Theme.of(context).colorScheme.enteTheme.shadowMenu,
-              color: warning500,
-            ),
-            child: Padding(
-              padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
-              child: Row(
-                mainAxisAlignment: MainAxisAlignment.spaceBetween,
-                children: [
-                  Icon(
-                    warningIcon,
-                    size: 36,
-                    color: Colors.white,
-                  ),
-                  const SizedBox(width: 12),
-                  Flexible(
-                    child: Text(
-                      text,
-                      style: darkTextTheme.bodyBold,
-                      textAlign: TextAlign.left,
-                    ),
-                  ),
-                  const SizedBox(width: 12),
-                  IconButtonWidget(
-                    icon: actionIcon,
-                    iconButtonType: IconButtonType.rounded,
-                    iconColor: strokeBaseDark,
-                    defaultColor: fillFaintDark,
-                    pressedColor: fillMutedDark,
-                    onTap: onTap,
-                  )
-                ],
-              ),
-            ),
-          ),
-        ),
-      ),
-    );
-  }
-}

+ 97 - 0
lib/ui/components/notification_widget.dart

@@ -0,0 +1,97 @@
+import 'package:flutter/material.dart';
+import 'package:photos/ente_theme_data.dart';
+import 'package:photos/theme/colors.dart';
+import 'package:photos/theme/text_style.dart';
+import 'package:photos/ui/components/icon_button_widget.dart';
+
+// CreateNotificationType enum
+enum NotificationType {
+  warning,
+  banner,
+}
+
+class NotificationWidget extends StatelessWidget {
+  final IconData startIcon;
+  final IconData actionIcon;
+  final String text;
+  final String? subText;
+  final GestureTapCallback onTap;
+  final NotificationType type;
+
+  const NotificationWidget({
+    Key? key,
+    required this.startIcon,
+    required this.actionIcon,
+    required this.text,
+    required this.onTap,
+    this.subText,
+    this.type = NotificationType.warning,
+  }) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    Color backgroundColor = Colors.white;
+    switch (type) {
+      case NotificationType.warning:
+        backgroundColor = warning500;
+        break;
+      case NotificationType.banner:
+        backgroundColor = backgroundElevated2Dark;
+        break;
+    }
+    return Center(
+      child: GestureDetector(
+        onTap: onTap,
+        child: Container(
+          decoration: BoxDecoration(
+            borderRadius: const BorderRadius.all(
+              Radius.circular(8),
+            ),
+            boxShadow: Theme.of(context).colorScheme.enteTheme.shadowMenu,
+            color: backgroundColor,
+          ),
+          child: Padding(
+            padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
+            child: Row(
+              mainAxisAlignment: MainAxisAlignment.spaceBetween,
+              children: [
+                Icon(
+                  startIcon,
+                  size: 36,
+                  color: Colors.white,
+                ),
+                const SizedBox(width: 12),
+                Column(
+                  crossAxisAlignment: CrossAxisAlignment.start,
+                  children: [
+                    Text(
+                      text,
+                      style: darkTextTheme.bodyBold,
+                      textAlign: TextAlign.left,
+                    ),
+                    subText != null
+                        ? Text(
+                            subText!,
+                            style: darkTextTheme.mini
+                                .copyWith(color: textMutedDark),
+                          )
+                        : const SizedBox.shrink(),
+                  ],
+                ),
+                const SizedBox(width: 12),
+                IconButtonWidget(
+                  icon: actionIcon,
+                  iconButtonType: IconButtonType.rounded,
+                  iconColor: strokeBaseDark,
+                  defaultColor: fillFaintDark,
+                  pressedColor: fillMutedDark,
+                  onTap: onTap,
+                )
+              ],
+            ),
+          ),
+        ),
+      ),
+    );
+  }
+}

+ 15 - 11
lib/ui/home/status_bar_widget.dart

@@ -97,17 +97,21 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
             ? HeaderErrorWidget(error: _syncError)
             : const SizedBox.shrink(),
         UserRemoteFlagService.instance.shouldShowRecoveryVerification()
-            ? NotificationWarningWidget(
-                warningIcon: Icons.error_outline,
-                actionIcon: Icons.arrow_forward,
-                text: "Confirm your recovery key",
-                onTap: () async => {
-                  await routeToPage(
-                    context,
-                    const VerifyRecoveryPage(),
-                    forceCustomPageRoute: true,
-                  )
-                },
+            ? Padding(
+                padding:
+                    const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12),
+                child: NotificationWidget(
+                  startIcon: Icons.error_outline,
+                  actionIcon: Icons.arrow_forward,
+                  text: "Confirm your recovery key",
+                  onTap: () async => {
+                    await routeToPage(
+                      context,
+                      const VerifyRecoveryPage(),
+                      forceCustomPageRoute: true,
+                    )
+                  },
+                ),
               )
             : const SizedBox.shrink()
       ],