createYaruTheme function

ThemeData createYaruTheme({
  1. required ColorScheme colorScheme,
  2. Color? dividerColor,
  3. Color? elevatedButtonColor,
  4. Color? elevatedButtonTextColor,
  5. bool? useMaterial3 = true,
})

Helper function to create a new Yaru theme

Implementation

ThemeData createYaruTheme({
  required ColorScheme colorScheme,
  Color? dividerColor,
  Color? elevatedButtonColor,
  Color? elevatedButtonTextColor,
  bool? useMaterial3 = true,
}) {
  dividerColor ??= colorScheme.isHighContrast
      ? colorScheme.outlineVariant
      : colorScheme.outline;
  final textTheme = createTextTheme(colorScheme.onSurface);

  if (isMobile) {
    return ThemeData(
      textTheme: textTheme,
      dividerColor: dividerColor,
      scaffoldBackgroundColor: colorScheme.surface,
      dividerTheme: DividerThemeData(
        color: dividerColor,
        space: 1.0,
        thickness: 1.0,
      ),
      useMaterial3: true,
      colorScheme: colorScheme,
    );
  }

  final themeData = ThemeData.from(
    useMaterial3: useMaterial3,
    colorScheme: colorScheme,
  );

  return themeData.copyWith(
    iconTheme: IconThemeData(
      color: colorScheme.onSurface,
      size: kCompactIconSize,
    ),
    primaryIconTheme: IconThemeData(color: colorScheme.onSurface),
    progressIndicatorTheme: _createProgressIndicatorTheme(colorScheme),
    pageTransitionsTheme: YaruPageTransitionsTheme.horizontal,
    tabBarTheme: _createTabBarTheme(colorScheme, dividerColor),
    dialogTheme: _createDialogTheme(colorScheme),
    brightness: colorScheme.brightness,
    primaryColor: colorScheme.primary,
    canvasColor: colorScheme.surface,
    scaffoldBackgroundColor: colorScheme.surface,
    cardColor: _cardColor(colorScheme),
    cardTheme: _createCardTheme(colorScheme),
    dividerColor: dividerColor,
    dialogBackgroundColor: colorScheme.surface,
    textTheme: textTheme,
    indicatorColor: colorScheme.primary,
    applyElevationOverlayColor: colorScheme.isDark,
    buttonTheme: _buttonThemeData,
    outlinedButtonTheme: _createOutlinedButtonTheme(
      colorScheme: colorScheme,
      disabledColor: themeData.disabledColor,
    ),
    elevatedButtonTheme: _createElevatedButtonTheme(
      color: elevatedButtonColor ?? colorScheme.primary,
      colorScheme: colorScheme,
      textColor: elevatedButtonTextColor,
      disabledColor: themeData.disabledColor,
    ),
    filledButtonTheme: _createFilledButtonTheme(
      colorScheme: colorScheme,
      disabledColor: themeData.disabledColor,
    ),
    textButtonTheme: _createTextButtonTheme(
      colorScheme: colorScheme,
      disabledColor: themeData.disabledColor,
    ),
    iconButtonTheme: _createIconButtonTheme(
      colorScheme: colorScheme,
      disabledColor: themeData.disabledColor,
    ),
    menuButtonTheme: _createMenuItemTheme(colorScheme, textTheme),
    switchTheme: _createSwitchTheme(colorScheme),
    checkboxTheme: _createCheckBoxTheme(colorScheme),
    radioTheme: _createRadioTheme(colorScheme),
    primaryColorDark: colorScheme.isDark ? colorScheme.primary : null,
    appBarTheme: _createAppBarTheme(colorScheme),
    floatingActionButtonTheme:
        _createFloatingActionButtonTheme(colorScheme, elevatedButtonColor),
    bottomNavigationBarTheme: BottomNavigationBarThemeData(
      selectedItemColor: colorScheme.primary,
      unselectedItemColor: colorScheme.onSurface.withOpacity(0.8),
    ),
    inputDecorationTheme: _createInputDecorationTheme(colorScheme),
    toggleButtonsTheme: _createToggleButtonsTheme(colorScheme),
    textSelectionTheme: _createTextSelectionTheme(colorScheme),
    dropdownMenuTheme: _createDropdownMenuTheme(colorScheme),
    menuTheme: _createMenuTheme(colorScheme),
    popupMenuTheme: _createPopupMenuTheme(colorScheme),
    tooltipTheme: _tooltipThemeData,
    bottomAppBarTheme: BottomAppBarTheme(color: colorScheme.surface),
    navigationBarTheme: _createNavigationBarTheme(colorScheme),
    navigationRailTheme: _createNavigationRailTheme(colorScheme),
    dividerTheme:
        DividerThemeData(color: dividerColor, space: 1.0, thickness: 0.0),
    badgeTheme: BadgeThemeData(
      backgroundColor: elevatedButtonColor ?? colorScheme.primary,
      textColor: contrastColor(elevatedButtonColor ?? colorScheme.primary),
    ),
    scrollbarTheme: const ScrollbarThemeData(
      mainAxisMargin: 3.0,
      crossAxisMargin: 3.0,
    ),
    splashFactory: NoSplash.splashFactory,
    sliderTheme: _createSliderTheme(colorScheme),
    drawerTheme: _createDrawerTheme(colorScheme),
    listTileTheme: ListTileThemeData(
      iconColor: colorScheme.onSurface.withOpacity(0.8),
    ),
    snackBarTheme: _createSnackBarTheme(colorScheme),
    chipTheme: _createChipTheme(
      selectedColor: elevatedButtonColor ?? colorScheme.primary,
      colorScheme: colorScheme,
    ),
  );
}