|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +ThemeData appTheme() { |
| 4 | + final TextTheme textTheme = _buildTextTheme(); |
| 5 | + final IconThemeData iconTheme = _buildIconTheme(); |
| 6 | + |
| 7 | + return ThemeData.light().copyWith( |
| 8 | + // Added in Flutter 1.17 |
| 9 | + visualDensity: VisualDensity.adaptivePlatformDensity, |
| 10 | + |
| 11 | + // Set default colors |
| 12 | + primaryColor: _AppColors.primary, |
| 13 | + accentColor: _AppColors.secondary, |
| 14 | + disabledColor: _AppColors.disabled, |
| 15 | + errorColor: _AppColors.error, |
| 16 | + |
| 17 | + // Customize Themes |
| 18 | + appBarTheme: _buildAppBarTheme(textTheme), |
| 19 | + iconTheme: iconTheme, |
| 20 | + primaryIconTheme: iconTheme.copyWith(color: _AppColors.primary), |
| 21 | + |
| 22 | + // Misc |
| 23 | + buttonTheme: ButtonThemeData( |
| 24 | + buttonColor: _AppColors.primary, |
| 25 | + textTheme: ButtonTextTheme.primary, |
| 26 | + ), |
| 27 | + unselectedWidgetColor: _AppColors.disabledWidget, |
| 28 | + textTheme: textTheme.apply( |
| 29 | + displayColor: _AppColors.primary, |
| 30 | + bodyColor: _AppColors.primary, |
| 31 | + ), |
| 32 | + ); |
| 33 | +} |
| 34 | + |
| 35 | +/// ******* Colors ******* |
| 36 | +class _AppColors { |
| 37 | + // Core |
| 38 | + // static const Color primary = Colors.green; |
| 39 | + static const Color primary = Color(0xFF042240); |
| 40 | + static const Color secondary = Color(0xFF018786); |
| 41 | + static Color error = Colors.red; |
| 42 | + static Color disabled = Colors.grey[500]; |
| 43 | + static Color disabledWidget = Colors.grey[300]; |
| 44 | +} |
| 45 | + |
| 46 | +/// ******* Custom Themes ******* |
| 47 | +AppBarTheme _buildAppBarTheme(TextTheme textTheme) { |
| 48 | + return AppBarTheme( |
| 49 | + textTheme: textTheme.apply(displayColor: _AppColors.primary), |
| 50 | + ); |
| 51 | +} |
| 52 | + |
| 53 | +IconThemeData _buildIconTheme() { |
| 54 | + return const IconThemeData(color: _AppColors.primary, size: 32); |
| 55 | +} |
| 56 | + |
| 57 | +/// ******* Text Theme ******* |
| 58 | +TextTheme _buildTextTheme() { |
| 59 | + return TextTheme( |
| 60 | + // Using default Material theme system |
| 61 | + // spec: https://material.io/design/typography/the-type-system.html#type-scale |
| 62 | + // on next stable release of Dart, display4 will be renamed to headline 1, |
| 63 | + // display 3 -> headline2, display2 -> headline3, etc. |
| 64 | + |
| 65 | + headline1: _AppTypography.h1, |
| 66 | + headline2: _AppTypography.h2, |
| 67 | + // Dashboard: Good day // Home: Hello world |
| 68 | + headline3: _AppTypography.h3, |
| 69 | + // CheckIn: Please select symptoms |
| 70 | + headline4: _AppTypography.h4, |
| 71 | + // CheckIn: Yesterday, you had.. |
| 72 | + headline5: _AppTypography.h5, |
| 73 | + // AppBar |
| 74 | + headline6: _AppTypography.h6, |
| 75 | + // ListTitle override 1 |
| 76 | + subtitle1: _AppTypography.subtitle1, |
| 77 | + // ListTitle override 2 |
| 78 | + subtitle2: _AppTypography.subtitle2, |
| 79 | + bodyText1: _AppTypography.bodyText1, |
| 80 | + // Default: Text Widget |
| 81 | + bodyText2: _AppTypography.bodyText2, |
| 82 | + // Default: Input error text |
| 83 | + caption: _AppTypography.caption, |
| 84 | + // Default: Button |
| 85 | + button: _AppTypography.button, |
| 86 | + overline: _AppTypography.overline, |
| 87 | + ); |
| 88 | +} |
| 89 | + |
| 90 | +/// ******* Custom Text ******* |
| 91 | +class _AppTypography { |
| 92 | + static const TextStyle h1 = TextStyle(fontSize: 96, fontWeight: FontWeight.w100); |
| 93 | + static const TextStyle h2 = TextStyle(fontSize: 60, fontWeight: FontWeight.w100); |
| 94 | + static const TextStyle h3 = TextStyle(fontSize: 32, fontWeight: FontWeight.w800); |
| 95 | + static const TextStyle h4 = TextStyle(fontSize: 24, fontWeight: FontWeight.w800); |
| 96 | + static const TextStyle h5 = TextStyle(fontSize: 20, fontWeight: FontWeight.w400); |
| 97 | + static const TextStyle h6 = TextStyle(fontSize: 22, fontWeight: FontWeight.bold); |
| 98 | + static const TextStyle subtitle1 = TextStyle(fontSize: 20, fontWeight: FontWeight.bold); |
| 99 | + static const TextStyle subtitle2 = TextStyle(fontSize: 18, fontWeight: FontWeight.w300); |
| 100 | + static const TextStyle bodyText1 = TextStyle(fontSize: 16, fontWeight: FontWeight.normal); |
| 101 | + static const TextStyle bodyText2 = TextStyle(fontSize: 36, fontWeight: FontWeight.normal); |
| 102 | + static const TextStyle caption = TextStyle(fontSize: 12, fontWeight: FontWeight.normal); |
| 103 | + static const TextStyle button = TextStyle(fontSize: 20, fontWeight: FontWeight.w400); |
| 104 | + static const TextStyle overline = TextStyle(fontSize: 10, fontWeight: FontWeight.normal); |
| 105 | +} |
0 commit comments