Browse Source

used enum for IconButton types

ashilkn 2 years ago
parent
commit
aba878a1fd

+ 1 - 1
lib/ui/backup_settings_screen.dart

@@ -29,7 +29,7 @@ class BackupSettingsScreen extends StatelessWidget {
             actionIcons: [
             actionIcons: [
               IconButtonWidget(
               IconButtonWidget(
                 icon: Icons.close_outlined,
                 icon: Icons.close_outlined,
-                isSecondary: true,
+                iconButtonType: IconButtonType.secondary,
                 onTap: () {
                 onTap: () {
                   Navigator.pop(context);
                   Navigator.pop(context);
                   Navigator.pop(context);
                   Navigator.pop(context);

+ 1 - 1
lib/ui/components/home_header_widget.dart

@@ -20,7 +20,7 @@ class _HomeHeaderWidgetState extends State<HomeHeaderWidget> {
       mainAxisAlignment: MainAxisAlignment.spaceBetween,
       mainAxisAlignment: MainAxisAlignment.spaceBetween,
       children: [
       children: [
         IconButtonWidget(
         IconButtonWidget(
-          isPrimary: true,
+          iconButtonType: IconButtonType.primary,
           icon: Icons.menu_outlined,
           icon: Icons.menu_outlined,
           onTap: () {
           onTap: () {
             Scaffold.of(context).openDrawer();
             Scaffold.of(context).openDrawer();

+ 15 - 12
lib/ui/components/icon_button_widget.dart

@@ -2,10 +2,14 @@ import 'package:flutter/material.dart';
 import 'package:photos/theme/colors.dart';
 import 'package:photos/theme/colors.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/theme/ente_theme.dart';
 
 
+enum IconButtonType {
+  primary,
+  secondary,
+  rounded,
+}
+
 class IconButtonWidget extends StatefulWidget {
 class IconButtonWidget extends StatefulWidget {
-  final bool isPrimary;
-  final bool isSecondary;
-  final bool isRounded;
+  final IconButtonType iconButtonType;
   final IconData icon;
   final IconData icon;
   final bool disableGestureDetector;
   final bool disableGestureDetector;
   final VoidCallback? onTap;
   final VoidCallback? onTap;
@@ -14,9 +18,7 @@ class IconButtonWidget extends StatefulWidget {
   final Color? iconColor;
   final Color? iconColor;
   const IconButtonWidget({
   const IconButtonWidget({
     required this.icon,
     required this.icon,
-    this.isPrimary = false,
-    this.isSecondary = false,
-    this.isRounded = false,
+    required this.iconButtonType,
     this.disableGestureDetector = false,
     this.disableGestureDetector = false,
     this.onTap,
     this.onTap,
     this.defaultColor,
     this.defaultColor,
@@ -41,13 +43,12 @@ class _IconButtonWidgetState extends State<IconButtonWidget> {
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
-    if (!widget.isPrimary && !widget.isRounded && !widget.isSecondary) {
-      return const SizedBox.shrink();
-    }
     final colorTheme = getEnteColorScheme(context);
     final colorTheme = getEnteColorScheme(context);
     iconStateColor ??
     iconStateColor ??
         (iconStateColor = widget.defaultColor ??
         (iconStateColor = widget.defaultColor ??
-            (widget.isRounded ? colorTheme.fillFaint : null));
+            (widget.iconButtonType == IconButtonType.rounded
+                ? colorTheme.fillFaint
+                : null));
     return widget.disableGestureDetector
     return widget.disableGestureDetector
         ? _iconButton(colorTheme)
         ? _iconButton(colorTheme)
         : GestureDetector(
         : GestureDetector(
@@ -72,7 +73,7 @@ class _IconButtonWidgetState extends State<IconButtonWidget> {
         child: Icon(
         child: Icon(
           widget.icon,
           widget.icon,
           color: widget.iconColor ??
           color: widget.iconColor ??
-              (widget.isSecondary
+              (widget.iconButtonType == IconButtonType.secondary
                   ? colorTheme.strokeMuted
                   ? colorTheme.strokeMuted
                   : colorTheme.strokeBase),
                   : colorTheme.strokeBase),
           size: 24,
           size: 24,
@@ -85,7 +86,9 @@ class _IconButtonWidgetState extends State<IconButtonWidget> {
     final colorTheme = getEnteColorScheme(context);
     final colorTheme = getEnteColorScheme(context);
     setState(() {
     setState(() {
       iconStateColor = widget.pressedColor ??
       iconStateColor = widget.pressedColor ??
-          (widget.isRounded ? colorTheme.fillMuted : colorTheme.fillFaint);
+          (widget.iconButtonType == IconButtonType.rounded
+              ? colorTheme.fillMuted
+              : colorTheme.fillFaint);
     });
     });
   }
   }
 
 

+ 1 - 1
lib/ui/components/notification_warning_widget.dart

@@ -54,7 +54,7 @@ class NotificationWarningWidget extends StatelessWidget {
                   const SizedBox(width: 12),
                   const SizedBox(width: 12),
                   IconButtonWidget(
                   IconButtonWidget(
                     icon: actionIcon,
                     icon: actionIcon,
-                    isRounded: true,
+                    iconButtonType: IconButtonType.rounded,
                     iconColor: strokeBaseDark,
                     iconColor: strokeBaseDark,
                     defaultColor: fillFaintDark,
                     defaultColor: fillFaintDark,
                     pressedColor: fillMutedDark,
                     pressedColor: fillMutedDark,

+ 10 - 7
lib/ui/components/title_bar_widget.dart

@@ -3,6 +3,7 @@ import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/ui/components/icon_button_widget.dart';
 import 'package:photos/ui/components/icon_button_widget.dart';
 
 
 class TitleBarWidget extends StatelessWidget {
 class TitleBarWidget extends StatelessWidget {
+  final IconButtonWidget? leading;
   final String? title;
   final String? title;
   final String? caption;
   final String? caption;
   final Widget? flexibleSpaceTitle;
   final Widget? flexibleSpaceTitle;
@@ -11,6 +12,7 @@ class TitleBarWidget extends StatelessWidget {
   final bool isTitleH2WithoutLeading;
   final bool isTitleH2WithoutLeading;
   final bool isFlexibleSpaceDisabled;
   final bool isFlexibleSpaceDisabled;
   const TitleBarWidget({
   const TitleBarWidget({
+    this.leading,
     this.title,
     this.title,
     this.caption,
     this.caption,
     this.flexibleSpaceTitle,
     this.flexibleSpaceTitle,
@@ -67,13 +69,14 @@ class TitleBarWidget extends StatelessWidget {
       ],
       ],
       leading: isTitleH2WithoutLeading
       leading: isTitleH2WithoutLeading
           ? null
           ? null
-          : IconButtonWidget(
-              icon: Icons.arrow_back_outlined,
-              isPrimary: true,
-              onTap: () {
-                Navigator.pop(context);
-              },
-            ),
+          : leading ??
+              IconButtonWidget(
+                icon: Icons.arrow_back_outlined,
+                iconButtonType: IconButtonType.primary,
+                onTap: () {
+                  Navigator.pop(context);
+                },
+              ),
       flexibleSpace: isFlexibleSpaceDisabled
       flexibleSpace: isFlexibleSpaceDisabled
           ? null
           ? null
           : FlexibleSpaceBar(
           : FlexibleSpaceBar(

+ 1 - 1
lib/ui/viewer/search/search_widget.dart

@@ -34,7 +34,7 @@ class _SearchIconWidgetState extends State<SearchIconWidget> {
     return Hero(
     return Hero(
       tag: "search_icon",
       tag: "search_icon",
       child: IconButtonWidget(
       child: IconButtonWidget(
-        isPrimary: true,
+        iconButtonType: IconButtonType.primary,
         icon: Icons.search,
         icon: Icons.search,
         onTap: () {
         onTap: () {
           Navigator.push(
           Navigator.push(