fromSeed static method
ThemeData
fromSeed({
- required Color seedColor,
- bool isDark = false,
- FontConfig? fontConfig,
- String fontFamily = 'Inter',
- TextDirection direction = TextDirection.ltr,
- double borderRadius = 12.0,
- VisualDensity? visualDensity,
Generates a ThemeData from a seed color.
seedColor: The primary seed color for the Material 3 color scheme.isDark: Whether to generate a dark or light theme.fontConfig: Direction-aware font configuration (preferred). Supports separate LTR and RTL fonts from Google Fonts or local assets.fontFamily: Legacy — a Google Font family name (e.g., 'Poppins'). UsefontConfiginstead for RTL support.direction: Text direction to use when resolvingfontConfig.borderRadius: Global border radius for buttons, cards, and inputs.visualDensity: UI density setting.
Implementation
static ThemeData fromSeed({
required Color seedColor,
bool isDark = false,
FontConfig? fontConfig,
String fontFamily = 'Inter',
TextDirection direction = TextDirection.ltr,
double borderRadius = 12.0,
VisualDensity? visualDensity,
}) {
final colorScheme = ColorScheme.fromSeed(
seedColor: seedColor,
brightness: isDark ? Brightness.dark : Brightness.light,
);
final TextTheme textTheme;
if (fontConfig != null) {
textTheme = fontConfig.resolveTextTheme(direction, ThemeData().textTheme);
} else {
textTheme = _buildTextTheme(fontFamily, colorScheme);
}
final radius = Radius.circular(borderRadius);
final shapeBorder = RoundedRectangleBorder(
borderRadius: BorderRadius.all(radius),
);
return ThemeData(
useMaterial3: true,
colorScheme: colorScheme,
brightness: isDark ? Brightness.dark : Brightness.light,
textTheme: textTheme,
visualDensity: visualDensity ?? VisualDensity.standard,
// Cards
cardTheme: CardThemeData(
elevation: 0,
shape: shapeBorder,
color: colorScheme.surfaceContainerLow,
),
// Buttons
filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom(
shape: shapeBorder,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 14),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
shape: shapeBorder,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 14),
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
shape: shapeBorder,
),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
shape: shapeBorder,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 14),
),
),
// Inputs
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: colorScheme.surfaceContainerHighest.withValues(alpha: 0.4),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(radius),
borderSide:
BorderSide(color: colorScheme.outline.withValues(alpha: 0.3)),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(radius),
borderSide:
BorderSide(color: colorScheme.outline.withValues(alpha: 0.3)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(radius),
borderSide: BorderSide(color: colorScheme.primary, width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(radius),
borderSide: BorderSide(color: colorScheme.error),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
),
// Dialogs
dialogTheme: DialogThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(borderRadius + 4)),
),
),
// Bottom sheets
bottomSheetTheme: BottomSheetThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(borderRadius + 8),
),
),
),
// Chips
chipTheme: ChipThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
),
),
// Page transitions
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.windows: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.linux: FadeUpwardsPageTransitionsBuilder(),
},
),
);
}