Selaa lähdekoodia

theme: minor refactoring

Neeraj Gupta 3 vuotta sitten
vanhempi
commit
bfd5d658ef
1 muutettua tiedostoa jossa 91 lisäystä ja 150 poistoa
  1. 91 150
      lib/app.dart

+ 91 - 150
lib/app.dart

@@ -24,37 +24,11 @@ final lightThemeData = ThemeData(
   colorScheme: ColorScheme.light(primary: Colors.black),
   accentColor: Color.fromRGBO(45, 194, 98, 0.2),
   buttonColor: Color.fromRGBO(45, 194, 98, 1.0),
-  outlinedButtonTheme: OutlinedButtonThemeData(
-    style: OutlinedButton.styleFrom(
-      shape: RoundedRectangleBorder(
-        borderRadius: BorderRadius.circular(8),
-      ),
-      padding: EdgeInsets.fromLTRB(50, 16, 50, 16),
-      alignment: Alignment.center,
-      textStyle: TextStyle(
-        fontWeight: FontWeight.w600,
-        fontFamily: 'Inter-SemiBold',
-        fontSize: 18,
-      ),
-    ).copyWith(
-      backgroundColor: MaterialStateProperty.resolveWith<Color>(
-        (Set<MaterialState> states) {
-          if (states.contains(MaterialState.disabled)) {
-            return Colors.grey.shade500;
-          }
-          return Colors.black;
-        },
-      ),
-      foregroundColor: MaterialStateProperty.resolveWith<Color>(
-        (Set<MaterialState> states) {
-          if (states.contains(MaterialState.disabled)) {
-            return Colors.white;
-          }
-          return Colors.white;
-        },
-      ),
-      alignment: Alignment.center,
-    ),
+  outlinedButtonTheme: _outlinedButtonThemeData(
+    bgDisabled: Colors.grey.shade500,
+    bgEnabled: Colors.black,
+    fgDisabled: Colors.white,
+    fgEnabled: Colors.white,
   ),
   elevatedButtonTheme: ElevatedButtonThemeData(
       style: ElevatedButton.styleFrom(
@@ -81,42 +55,7 @@ final lightThemeData = ThemeData(
       foregroundColor: Colors.black,
       iconTheme: IconThemeData(color: Colors.black)),
   //https://api.flutter.dev/flutter/material/TextTheme-class.html
-  textTheme: TextTheme().copyWith(
-      headline4: TextStyle(
-        color: Colors.black,
-        fontSize: 32,
-        fontWeight: FontWeight.w600,
-        fontFamily: 'Inter-SemiBold',
-      ),
-      headline5: TextStyle(
-        color: Colors.black,
-        fontSize: 24,
-        fontWeight: FontWeight.w600,
-        fontFamily: 'Inter-SemiBold',
-      ),
-      headline6: TextStyle(
-          color: Colors.black,
-          fontFamily: 'Inter-Medium',
-          fontSize: 18,
-          fontWeight: FontWeight.w600),
-      subtitle1: TextStyle(
-          fontFamily: 'Inter-Medium',
-          color: Colors.black,
-          fontSize: 16,
-          fontWeight: FontWeight.w500), // medium body weight
-      bodyText1: TextStyle(
-          fontFamily: 'Inter-Medium',
-          color: Colors.black,
-          fontSize: 16,
-          fontWeight: FontWeight.w400),
-      bodyText2: TextStyle(
-          fontFamily: 'Inter-Medium',
-          color: Colors.black,
-          fontSize: 16,
-          fontWeight: FontWeight.w400),
-      caption: TextStyle(color: Colors.black.withOpacity(0.7), fontSize: 14),
-      overline: TextStyle(color: Colors.black.withOpacity(0.8), fontSize: 12)),
-
+  textTheme: _buildTextTheme(Colors.black),
   primaryTextTheme: TextTheme().copyWith(
       bodyText2: TextStyle(color: Colors.yellow),
       bodyText1: TextStyle(color: Colors.orange)),
@@ -147,18 +86,14 @@ final lightThemeData = ThemeData(
       width: 2,
     ),
     fillColor: MaterialStateProperty.resolveWith((states) {
-      if (states.contains(MaterialState.selected)) {
-        return Colors.black;
-      } else {
-        return Colors.white;
-      }
+      return states.contains(MaterialState.selected)
+          ? Colors.black
+          : Colors.white;
     }),
     checkColor: MaterialStateProperty.resolveWith((states) {
-      if (states.contains(MaterialState.selected)) {
-        return Colors.white;
-      } else {
-        return Colors.black;
-      }
+      return states.contains(MaterialState.selected)
+          ? Colors.white
+          : Colors.black;
     }),
   ),
 );
@@ -178,75 +113,13 @@ final darkThemeData = ThemeData(
     buttonColor: Color.fromRGBO(45, 194, 98, 1.0),
   ),
   // primaryColor: Colors.red,
-  textTheme: TextTheme().copyWith(
-      headline4: TextStyle(
-        color: Colors.white,
-        fontSize: 32,
-        fontWeight: FontWeight.w600,
-        fontFamily: 'Inter-SemiBold',
-      ),
-      headline5: TextStyle(
-        color: Colors.white,
-        fontSize: 24,
-        fontWeight: FontWeight.w600,
-        fontFamily: 'Inter-SemiBold',
-      ),
-      headline6: TextStyle(
-          color: Colors.white,
-          fontSize: 18,
-          fontFamily: 'Inter-Medium',
-          fontWeight: FontWeight.w600),
-      subtitle1: TextStyle(
-          color: Colors.white,
-          fontFamily: 'Inter-Medium',
-          fontSize: 16,
-          fontWeight: FontWeight.w500),
-      bodyText1: TextStyle(
-          fontFamily: 'Inter-Medium',
-          color: Colors.white,
-          fontSize: 16,
-          fontWeight: FontWeight.w400),
-      caption: TextStyle(
-        color: Colors.white.withOpacity(0.6),
-        fontSize: 14,
-      ),
-      overline: TextStyle(
-        color: Colors.white.withOpacity(0.8),
-        fontSize: 12,
-      )),
+  textTheme: _buildTextTheme(Colors.white),
   toggleableActiveColor: Colors.green[400],
-  outlinedButtonTheme: OutlinedButtonThemeData(
-    style: OutlinedButton.styleFrom(
-      shape: RoundedRectangleBorder(
-        borderRadius: BorderRadius.circular(8),
-      ),
-      alignment: Alignment.center,
-      padding: EdgeInsets.fromLTRB(50, 16, 50, 16),
-      textStyle: TextStyle(
-        fontWeight: FontWeight.w600,
-        fontFamily: 'Inter-SemiBold',
-        fontSize: 18,
-      ),
-    ).copyWith(
-      backgroundColor: MaterialStateProperty.resolveWith<Color>(
-        (Set<MaterialState> states) {
-          if (states.contains(MaterialState.disabled)) {
-            return Colors.grey.shade500;
-          }
-          return Colors.white;
-        },
-      ),
-      foregroundColor: MaterialStateProperty.resolveWith<Color>(
-        (Set<MaterialState> states) {
-          if (states.contains(MaterialState.disabled)) {
-            return Colors.white;
-          }
-          return Colors.black;
-        },
-      ),
-      alignment: Alignment.center,
-    ),
-  ),
+  outlinedButtonTheme: _outlinedButtonThemeData(
+      bgDisabled: Colors.grey.shade500,
+      bgEnabled: Colors.white,
+      fgDisabled: Colors.white,
+      fgEnabled: Colors.black),
   elevatedButtonTheme: ElevatedButtonThemeData(
       style: ElevatedButton.styleFrom(
     onPrimary: Colors.black,
@@ -311,12 +184,80 @@ final darkThemeData = ThemeData(
   ),
 );
 
-// class AppColors {
-//   final green = const Color(0xFF58BB54);
-//   const AppColors();
-// }
+TextTheme _buildTextTheme(Color textColor) {
+  return TextTheme().copyWith(
+      headline4: TextStyle(
+        color: textColor,
+        fontSize: 32,
+        fontWeight: FontWeight.w600,
+        fontFamily: 'Inter-SemiBold',
+      ),
+      headline5: TextStyle(
+        color: textColor,
+        fontSize: 24,
+        fontWeight: FontWeight.w600,
+        fontFamily: 'Inter-SemiBold',
+      ),
+      headline6: TextStyle(
+          color: textColor,
+          fontSize: 18,
+          fontFamily: 'Inter-Medium',
+          fontWeight: FontWeight.w600),
+      subtitle1: TextStyle(
+          color: textColor,
+          fontFamily: 'Inter-Medium',
+          fontSize: 16,
+          fontWeight: FontWeight.w500),
+      bodyText1: TextStyle(
+          fontFamily: 'Inter-Medium',
+          color: textColor,
+          fontSize: 16,
+          fontWeight: FontWeight.w400),
+      caption: TextStyle(
+        color: textColor.withOpacity(0.6),
+        fontSize: 14,
+      ),
+      overline: TextStyle(
+        color: textColor.withOpacity(0.8),
+        fontSize: 12,
+      ));
+}
 
-// const colors = AppColors();
+OutlinedButtonThemeData _outlinedButtonThemeData(
+    {Color bgDisabled, Color bgEnabled, Color fgDisabled, Color fgEnabled}) {
+  return OutlinedButtonThemeData(
+    style: OutlinedButton.styleFrom(
+      shape: RoundedRectangleBorder(
+        borderRadius: BorderRadius.circular(8),
+      ),
+      alignment: Alignment.center,
+      padding: EdgeInsets.fromLTRB(50, 16, 50, 16),
+      textStyle: TextStyle(
+        fontWeight: FontWeight.w600,
+        fontFamily: 'Inter-SemiBold',
+        fontSize: 18,
+      ),
+    ).copyWith(
+      backgroundColor: MaterialStateProperty.resolveWith<Color>(
+        (Set<MaterialState> states) {
+          if (states.contains(MaterialState.disabled)) {
+            return bgDisabled;
+          }
+          return bgEnabled;
+        },
+      ),
+      foregroundColor: MaterialStateProperty.resolveWith<Color>(
+        (Set<MaterialState> states) {
+          if (states.contains(MaterialState.disabled)) {
+            return fgDisabled;
+          }
+          return fgEnabled;
+        },
+      ),
+      alignment: Alignment.center,
+    ),
+  );
+}
 
 class EnteApp extends StatefulWidget {
   static const _homeWidget = HomeWidget();