| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import 'dart:io';
- import 'package:flutter/material.dart';
- import '../../app/data/sp/ix_sp.dart';
- import 'theme_extensions/theme_extension.dart';
- import 'dark_theme_colors.dart';
- import 'ix_styles.dart';
- import 'light_theme_colors.dart';
- class IXTheme {
- static getThemeData({required bool isLight}) {
- return ThemeData(
- fontFamilyFallback: Platform.isWindows ? ["Microsoft YaHei"] : [],
- // main color (app bar,tabs..etc)
- primaryColor: isLight
- ? LightThemeColors.primaryColor
- : DarkThemeColors.primaryColor,
- shadowColor: isLight
- ? LightThemeColors.shadowColor
- : DarkThemeColors.shadowColor,
- // secondary & background color
- colorScheme:
- ColorScheme.fromSwatch(
- accentColor: isLight
- ? LightThemeColors.accentColor
- : DarkThemeColors.accentColor,
- backgroundColor: isLight
- ? LightThemeColors.backgroundColor
- : DarkThemeColors.backgroundColor,
- brightness: isLight ? Brightness.light : Brightness.dark,
- ).copyWith(
- secondary: isLight
- ? LightThemeColors.accentColor
- : DarkThemeColors.accentColor,
- ),
- // color contrast (if the theme is dark text should be white for example)
- brightness: isLight ? Brightness.light : Brightness.dark,
- // card widget background color
- cardColor: isLight
- ? LightThemeColors.cardColor
- : DarkThemeColors.cardColor,
- // hint text color
- hintColor: isLight
- ? LightThemeColors.hintTextColor
- : DarkThemeColors.hintTextColor,
- canvasColor: isLight
- ? LightThemeColors.bgDisable
- : DarkThemeColors.bgDisable,
- splashColor: isLight ? LightThemeColors.bgScrim : DarkThemeColors.bgScrim,
- // divider color
- dividerColor: isLight
- ? LightThemeColors.dividerColor
- : DarkThemeColors.dividerColor,
- // app background color
- scaffoldBackgroundColor: isLight
- ? LightThemeColors.scaffoldBackgroundColor
- : DarkThemeColors.scaffoldBackgroundColor,
- highlightColor: isLight
- ? LightThemeColors.backgroundColor
- : DarkThemeColors.backgroundColor,
- // progress bar theme
- progressIndicatorTheme: ProgressIndicatorThemeData(
- color: isLight ? LightThemeColors.strokes2 : DarkThemeColors.strokes2,
- ),
- // appBar theme
- appBarTheme: IXStyles.getAppBarTheme(isLightTheme: isLight),
- // elevated button theme
- elevatedButtonTheme: IXStyles.getElevatedButtonTheme(
- isLightTheme: isLight,
- ),
- // text theme
- textTheme: IXStyles.getTextTheme(isLightTheme: isLight),
- // chip theme
- chipTheme: IXStyles.getChipTheme(isLightTheme: isLight),
- // icon theme
- iconTheme: IXStyles.getIconTheme(isLightTheme: isLight),
- // list tile theme
- listTileTheme: IXStyles.getListTileThemeData(isLightTheme: isLight),
- // custom themes
- extensions: [],
- );
- }
- /// update app theme and save theme type to shared pref
- /// (so when the app is killed and up again theme will remain the same)
- static changeTheme() {
- ReactiveTheme.toggleTheme();
- }
- /// check if the theme is light or dark
- bool get getThemeIsLight => IXSP.getThemeIsLight();
- }
|