Files
eatvio_app/lib/theme/theme_helper.dart

194 lines
5.8 KiB
Dart

import 'package:flutter/material.dart';
import '../../core/app_export.dart';
/// Helper class for managing themes and colors.
class ThemeHelper {
// The current app theme
var _appTheme = PrefUtils().getThemeData();
// A map of custom color themes supported by the app
Map<String, PrimaryColors> _supportedCustomColor = {
'primary': PrimaryColors()
};
// A map of color schemes supported by the app
Map<String, ColorScheme> _supportedColorScheme = {
'primary': ColorSchemes.primaryColorScheme
};
/// Returns the primary colors for the current theme.
PrimaryColors _getThemeColors() {
//throw exception to notify given theme is not found or not generated by the generator
if (!_supportedCustomColor.containsKey(_appTheme)) {
throw Exception(
"$_appTheme is not found.Make sure you have added this theme class in JSON Try running flutter pub run build_runner");
}
//return theme from map
return _supportedCustomColor[_appTheme] ?? PrimaryColors();
}
/// Returns the current theme data.
ThemeData _getThemeData() {
//throw exception to notify given theme is not found or not generated by the generator
if (!_supportedColorScheme.containsKey(_appTheme)) {
throw Exception(
"$_appTheme is not found.Make sure you have added this theme class in JSON Try running flutter pub run build_runner");
}
//return theme from map
var colorScheme =
_supportedColorScheme[_appTheme] ?? ColorSchemes.primaryColorScheme;
return ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
visualDensity: VisualDensity.standard,
colorScheme: colorScheme,
textTheme: TextThemes.textTheme(colorScheme),
scaffoldBackgroundColor: colorScheme.onPrimary,
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
backgroundColor: Colors.transparent,
side: BorderSide(
color: colorScheme.primary,
width: 1.h,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.h),
),
visualDensity: const VisualDensity(
vertical: -4,
horizontal: -4,
),
padding: EdgeInsets.zero,
),
),
);
}
/// Returns the primary colors for the current theme.
PrimaryColors themeColor() => _getThemeColors();
/// Returns the current theme data.
ThemeData themeData() => _getThemeData();
}
/// Class containing the supported text theme styles.
class TextThemes {
static TextTheme textTheme(ColorScheme colorScheme) => TextTheme(
bodyLarge: TextStyle(
color: appTheme.blueGray400,
fontSize: 18.fSize,
fontFamily: 'Mulish',
fontWeight: FontWeight.w400,
),
headlineSmall: TextStyle(
color: colorScheme.primary,
fontSize: 24.fSize,
fontFamily: 'Segoe UI',
fontWeight: FontWeight.w600,
),
titleMedium: TextStyle(
color: colorScheme.primary,
fontSize: 18.fSize,
fontFamily: 'Mulish',
fontWeight: FontWeight.w700,
),
titleSmall: TextStyle(
color: colorScheme.onPrimary,
fontSize: 15.fSize,
fontFamily: 'Mulish',
fontWeight: FontWeight.w700,
),
bodyMedium: TextStyle(
color: appTheme.blueGray400,
fontSize: 14.fSize,
fontFamily: 'Mulish',
fontWeight: FontWeight.w400,
),
bodySmall: TextStyle(
color: appTheme.gray500,
fontSize: 10.fSize,
fontFamily: 'Roboto',
fontWeight: FontWeight.w400,
),
labelLarge: TextStyle(
color: appTheme.blueGray800,
fontSize: 12.fSize,
fontFamily: 'Mulish',
fontWeight: FontWeight.w600,
),
);
}
/// Class containing the supported color schemes.
class ColorSchemes {
static final primaryColorScheme = ColorScheme.light(
// Primary colors
primary: Color(0XFF323F4B),
// On colors(text colors)
onPrimary: Color(0XFFFFFFFF),
onPrimaryContainer: Color(0XFF0B3F56),
);
}
/// Class containing custom colors for a primary theme.
class PrimaryColors {
// Blue
Color get blue400 => Color(0XFF43A6F2);
Color get blueA400 => Color(0XFF2F80ED);
// BlueGray
Color get blueGray400 => Color(0XFF7B8794);
Color get black900 => Color(0XFF000000);
// Blue
Color get blue800 => Color(0XFF1F78B4);
// BlueGray
Color get blueGray300 => Color(0XFF9AA5B1);
Color get blueGray800 => Color(0XFF323F4B);
Color get blueGray900 => Color(0XFF2A2F4C);
// DeepOrange
Color get deepOrange900 => Color(0XFF9A4A00);
// Gray
Color get gray100 => Color(0XFFF0F2F5);
Color get gray200 => Color(0XFFF0F0F0);
Color get gray400 => Color(0XFFC1C1C1);
Color get gray40001 => Color(0XFFC8C8C8);
Color get gray50 => Color(0XFFF6FAFF);
Color get gray500 => Color(0XFFA3A3A3);
Color get gray600 => Color(0XFF6D6D6D);
Color get gray60001 => Color(0XFF848484);
Color get gray60002 => Color(0XFF757575);
Color get gray60003 => Color(0XFF707070);
// Green
Color get greenA700 => Color(0XFF019A3E);
Color get greenA70001 => Color(0XFF00BE13);
// LightGreen
Color get lightGreen300 => Color(0XFFB2DF8A);
Color get lightGreenA700 => Color(0XFF18FF14);
// Red
Color get red200 => Color(0XFFE3A6A6);
// Teal
Color get teal100 => Color(0XFFA6CEE3);
Color get teal900 => Color(0XFF0B3F56);
// White
Color get whiteA700 => Color(0XFFFFFFFF);
}
PrimaryColors get appTheme => ThemeHelper().themeColor();
ThemeData get theme => ThemeHelper().themeData();