shadMaterialThemeFrom function
Derives the Material ThemeData a ShadThemeData implies: its colours, font, divider, text selection, icon and scrollbar themes.
ShadMaterial installs it. Call it yourself to theme a MaterialApp
built by ShadApp.custom:
ShadApp.custom(
appBuilder: (context) => MaterialApp(
theme: shadMaterialThemeFrom(ShadTheme.of(context)),
builder: (context, child) => ShadAppBuilder(child: child!),
),
)
Implementation
ThemeData shadMaterialThemeFrom(ShadThemeData themeData) {
final theme = ThemeData(
fontFamily: themeData.textTheme.family,
colorScheme: ColorScheme(
brightness: themeData.brightness,
primary: themeData.colorScheme.primary,
onPrimary: themeData.colorScheme.primaryForeground,
secondary: themeData.colorScheme.secondary,
onSecondary: themeData.colorScheme.secondaryForeground,
error: themeData.colorScheme.destructive,
onError: themeData.colorScheme.destructiveForeground,
surface: themeData.colorScheme.background,
onSurface: themeData.colorScheme.foreground,
),
scaffoldBackgroundColor: themeData.colorScheme.background,
brightness: themeData.brightness,
dividerTheme: DividerThemeData(
color: themeData.separatorTheme.color ?? themeData.colorScheme.border,
thickness: themeData.separatorTheme.thickness ?? 1,
),
textSelectionTheme: TextSelectionThemeData(
cursorColor: themeData.colorScheme.primary,
selectionColor: themeData.colorScheme.selection,
selectionHandleColor: themeData.colorScheme.primary,
),
iconTheme: IconThemeData(
size: 16,
color: themeData.colorScheme.foreground,
),
scrollbarTheme: ScrollbarThemeData(
crossAxisMargin: 1,
mainAxisMargin: 1,
thickness: const WidgetStatePropertyAll(8),
radius: const Radius.circular(999),
thumbColor: WidgetStatePropertyAll(themeData.colorScheme.border),
),
);
final builder = themeData.textTheme.googleFontBuilder;
if (builder == null) return theme;
return theme.copyWith(textTheme: _withFontBuilder(theme.textTheme, builder));
}