toThemeData method

ThemeData toThemeData()

Conversion to theme data.

Implementation

ThemeData toThemeData() {
  switch (brightness) {
    case Brightness.dark:
      final colorScheme = const ColorScheme.dark().copyWith(
        primary: primary,
        primaryVariant: primaryVariant,
        secondary: secondary,
        secondaryVariant: secondaryVariant,
        surface: surface,
        background: background,
        error: error,
        onPrimary: onPrimary,
        onSecondary: onSecondary,
        onBackground: onBackground,
        onSurface: onSurface,
        onError: onError,
        brightness: brightness,
      );
      final theme = ThemeData.dark();
      return theme.copyWith(
        platform: TargetPlatform.iOS,
        colorScheme: colorScheme,
        splashColor: const Color(0xFFFFFFFF).withOpacity(0.8),
        buttonColor: primary,
        textTheme: theme.textTheme.apply(
          bodyColor: onBackground,
          displayColor: onBackground,
          fontFamily: fontFamily,
        ),
        appBarTheme: appBarColor != null
            ? theme.appBarTheme.copyWith(
                backgroundColor: appBarColor,
                elevation: appBarColor == Colors.transparent ? 0 : null,
                foregroundColor:
                    appBarColor == Colors.transparent ? onBackground : null,
                textTheme: appBarColor == Colors.transparent
                    ? theme.textTheme.copyWith().apply(
                          bodyColor: onBackground,
                          displayColor: onBackground,
                        )
                    : null,
                iconTheme: appBarColor == Colors.transparent
                    ? theme.iconTheme.copyWith(
                        color: onBackground,
                      )
                    : null,
                actionsIconTheme: appBarColor == Colors.transparent
                    ? theme.iconTheme.copyWith(
                        color: onBackground,
                      )
                    : null,
              )
            : null,
        buttonTheme: theme.buttonTheme.copyWith(
          textTheme: theme.buttonTheme.textTheme,
          buttonColor: primary,
          disabledColor: disabled,
          colorScheme: colorScheme,
        ),
        inputDecorationTheme: theme.inputDecorationTheme.copyWith(
          labelStyle: TextStyle(color: weak),
          helperStyle: TextStyle(color: weak),
          hintStyle: TextStyle(color: weak),
          counterStyle: TextStyle(color: weak),
          errorStyle: TextStyle(color: error),
          prefixStyle: TextStyle(color: onBackground),
          suffixStyle: TextStyle(color: onBackground),
          border: OutlineInputBorder(
            borderSide: BorderSide(color: weak, width: 2),
          ),
          enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(color: weak, width: 2),
          ),
          disabledBorder: OutlineInputBorder(
            borderSide: BorderSide(color: weak, width: 2),
          ),
          focusedBorder: OutlineInputBorder(
            borderSide: BorderSide(color: primary, width: 2),
          ),
          errorBorder: OutlineInputBorder(
            borderSide: BorderSide(color: error, width: 2),
          ),
          focusedErrorBorder: OutlineInputBorder(
            borderSide: BorderSide(color: error, width: 2),
          ),
        ),
        indicatorColor: secondary,
        brightness: brightness,
        primaryColorBrightness: brightness,
        primaryColor: primary,
        accentColor: secondary,
        disabledColor: disabled,
        dividerColor: weak,
        errorColor: error,
        backgroundColor: background,
        canvasColor: background,
      );
    default:
      final colorScheme = const ColorScheme.light().copyWith(
          primary: primary,
          primaryVariant: primaryVariant,
          secondary: secondary,
          secondaryVariant: secondaryVariant,
          surface: surface,
          background: background,
          error: error,
          onPrimary: onPrimary,
          onSecondary: onSecondary,
          onBackground: onBackground,
          onSurface: onSurface,
          onError: onError,
          brightness: brightness);
      final theme = ThemeData.light();
      return theme.copyWith(
        platform: TargetPlatform.iOS,
        colorScheme: colorScheme,
        splashColor: const Color(0xFFFFFFFF).withOpacity(0.8),
        buttonColor: primary,
        appBarTheme: appBarColor != null
            ? theme.appBarTheme.copyWith(
                backgroundColor: appBarColor,
                elevation: appBarColor == Colors.transparent ? 0 : null,
                foregroundColor:
                    appBarColor == Colors.transparent ? onBackground : null,
                textTheme: appBarColor == Colors.transparent
                    ? theme.textTheme.copyWith().apply(
                          bodyColor: onBackground,
                          displayColor: onBackground,
                        )
                    : null,
                iconTheme: appBarColor == Colors.transparent
                    ? theme.iconTheme.copyWith(
                        color: onBackground,
                      )
                    : null,
                actionsIconTheme: appBarColor == Colors.transparent
                    ? theme.iconTheme.copyWith(
                        color: onBackground,
                      )
                    : null,
              )
            : null,
        textTheme: theme.textTheme.apply(
          bodyColor: onBackground,
          displayColor: onBackground,
          fontFamily: fontFamily,
        ),
        buttonTheme: theme.buttonTheme.copyWith(
          buttonColor: primary,
          disabledColor: disabled,
          colorScheme: colorScheme,
        ),
        inputDecorationTheme: theme.inputDecorationTheme.copyWith(
          labelStyle: TextStyle(color: weak),
          helperStyle: TextStyle(color: weak),
          hintStyle: TextStyle(color: weak),
          counterStyle: TextStyle(color: weak),
          errorStyle: TextStyle(color: error),
          prefixStyle: TextStyle(color: onBackground),
          suffixStyle: TextStyle(color: onBackground),
          border: OutlineInputBorder(
            borderSide: BorderSide(color: weak, width: 2),
          ),
          enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(color: weak, width: 2),
          ),
          disabledBorder: OutlineInputBorder(
            borderSide: BorderSide(color: weak, width: 2),
          ),
          focusedBorder: OutlineInputBorder(
            borderSide: BorderSide(color: primary, width: 2),
          ),
          errorBorder: OutlineInputBorder(
            borderSide: BorderSide(color: error, width: 2),
          ),
          focusedErrorBorder: OutlineInputBorder(
            borderSide: BorderSide(color: error, width: 2),
          ),
        ),
        indicatorColor: secondary,
        brightness: brightness,
        primaryColorBrightness: brightness,
        primaryColor: primary,
        accentColor: secondary,
        disabledColor: disabled,
        dividerColor: weak,
        errorColor: error,
        backgroundColor: background,
        canvasColor: background,
      );
  }
}