forked from eatvio/eatvio_app
New screen names
This commit is contained in:
128
lib/theme/theme_helper.dart
Normal file
128
lib/theme/theme_helper.dart
Normal file
@@ -0,0 +1,128 @@
|
||||
import 'dart:ui';
|
||||
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(
|
||||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
PrimaryColors get appTheme => ThemeHelper().themeColor();
|
||||
ThemeData get theme => ThemeHelper().themeData();
|
||||
Reference in New Issue
Block a user