themeData method

ThemeData themeData(
  1. Color? themeColor, {
  2. bool light = false,
})

Build a ThemeData with the given themeColor for the picker. 为选择器构建基于 themeColorThemeData

If themeColor is null, the color will use the fallback defaultThemeColorWeChat which is the default color in the WeChat design. 如果 themeColor 为 null,主题色将回落使用 defaultThemeColorWeChat, 即微信设计中的绿色主题色。

Set light to true if pickers require a light version of the theme. 设置 light 为 true 时可以获取浅色版本的主题。

Implementation

ThemeData themeData(Color? themeColor, {bool light = false}) {
  themeColor ??= defaultThemeColorWeChat;
  if (light) {
    return ThemeData.light().copyWith(
      primaryColor: Colors.grey[50],
      primaryColorLight: Colors.grey[50],
      primaryColorDark: Colors.grey[50],
      canvasColor: Colors.grey[100],
      scaffoldBackgroundColor: Colors.grey[50],
      cardColor: Colors.grey[50],
      highlightColor: Colors.transparent,
      textSelectionTheme: TextSelectionThemeData(
        cursorColor: themeColor,
        selectionColor: themeColor.withAlpha(100),
        selectionHandleColor: themeColor,
      ),
      indicatorColor: themeColor,
      appBarTheme: const AppBarTheme(
        systemOverlayStyle: SystemUiOverlayStyle(
          statusBarBrightness: Brightness.light,
          statusBarIconBrightness: Brightness.dark,
        ),
        elevation: 0,
      ),
      buttonTheme: ButtonThemeData(buttonColor: themeColor),
      colorScheme: ColorScheme(
        primary: Colors.grey[50]!,
        secondary: themeColor,
        background: Colors.grey[50]!,
        surface: Colors.grey[50]!,
        brightness: Brightness.light,
        error: const Color(0xffcf6679),
        onPrimary: Colors.white,
        onSecondary: Colors.white,
        onSurface: Colors.black,
        onBackground: Colors.black,
        onError: Colors.white,
      ),
    );
  }
  return ThemeData.dark().copyWith(
    primaryColor: Colors.grey[900],
    primaryColorLight: Colors.grey[900],
    primaryColorDark: Colors.grey[900],
    canvasColor: Colors.grey[850],
    scaffoldBackgroundColor: Colors.grey[900],
    cardColor: Colors.grey[900],
    highlightColor: Colors.transparent,
    textSelectionTheme: TextSelectionThemeData(
      cursorColor: themeColor,
      selectionColor: themeColor.withAlpha(100),
      selectionHandleColor: themeColor,
    ),
    indicatorColor: themeColor,
    appBarTheme: const AppBarTheme(
      systemOverlayStyle: SystemUiOverlayStyle(
        statusBarBrightness: Brightness.dark,
        statusBarIconBrightness: Brightness.light,
      ),
      elevation: 0,
    ),
    buttonTheme: ButtonThemeData(buttonColor: themeColor),
    colorScheme: ColorScheme(
      primary: Colors.grey[900]!,
      secondary: themeColor,
      background: Colors.grey[900]!,
      surface: Colors.grey[900]!,
      brightness: Brightness.dark,
      error: const Color(0xffcf6679),
      onPrimary: Colors.black,
      onSecondary: Colors.black,
      onSurface: Colors.white,
      onBackground: Colors.white,
      onError: Colors.black,
    ),
  );
}