copyTheme static method

ThemeData copyTheme(
  1. Color themeColor, {
  2. Color? appBarColor,
  3. bool centerTitle = true,
  4. bool isDarkMode = false,
  5. bool useMaterial3 = false,
})

Implementation

static ThemeData copyTheme(Color themeColor,
    {Color? appBarColor, bool centerTitle = true, bool isDarkMode = false, bool useMaterial3 = false}) {
  return (isDarkMode ? ThemeData.dark(useMaterial3: useMaterial3) : ThemeData.light(useMaterial3: useMaterial3))
      .copyWith(
    primaryColor: themeColor,
    //默认的主题色
    // primaryColorBrightness: isDarkMode ? Brightness.dark : Brightness.light,
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ButtonStyle(backgroundColor: MaterialStateProperty.all<Color>(themeColor)),
    ),
    colorScheme: isDarkMode
        ? ColorScheme.dark(
            secondary: themeColor,
            primary: themeColor,
            onSecondary: themeColor,
          )
        : ColorScheme.light(
            secondary: themeColor,
            primary: themeColor,
            onSecondary: themeColor,
          ),
    // toggleableActiveColor: themeColor,
    appBarTheme: AppBarTheme(centerTitle: centerTitle, backgroundColor: appBarColor),
  );
}