materialThemeFrom function
Derives the Material m.ThemeData a UnaThemeData implies: its colours, font, divider, text selection, icon and scrollbar themes.
UnaMaterial installs it. Call it yourself to theme a MaterialApp
built by UnaApp.custom:
UnaApp.custom(
appBuilder: (context) => MaterialApp(
theme: materialThemeFrom(UnaTheme.of(context)),
builder: (context, child) => UnaAppBuilder(child: child!),
),
)
Implementation
m.ThemeData materialThemeFrom(UnaThemeData themeData) {
final theme = m.ThemeData(
fontFamily: themeData.textTheme.family,
colorScheme: m.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.dividerTheme.color ?? themeData.colorScheme.border,
thickness: themeData.dividerTheme.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));
}