Fluent2ThemeData constructor
Fluent2ThemeData({
- MixedFluentTextTheme? fluentTextTheme,
- MixedFluentStrokeTheme? fluentStrokeTheme,
- MixedFluentShadowTheme? fluentShadowTheme,
- FluentColors? fluentBrandColors,
- Iterable<
Adaptation< ? adaptations,Object> > - bool? applyElevationOverlayColor,
- NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
- Iterable<
ThemeExtension> ? extensions, - Object? inputDecorationTheme,
- MaterialTapTargetSize? materialTapTargetSize,
- PageTransitionsTheme? pageTransitionsTheme,
- TargetPlatform? platform,
- ScrollbarThemeData? scrollbarTheme,
- InteractiveInkFeatureFactory? splashFactory,
- bool? useMaterial3,
- VisualDensity? visualDensity,
- Brightness? brightness,
- Color? canvasColor,
- Color? cardColor,
- ColorScheme? colorScheme,
- Color? colorSchemeSeed,
- Color? dialogBackgroundColor,
- Color? disabledColor,
- Color? dividerColor,
- Color? focusColor,
- Color? highlightColor,
- Color? hintColor,
- Color? hoverColor,
- Color? indicatorColor,
- Color? primaryColor,
- Color? primaryColorDark,
- Color? primaryColorLight,
- MaterialColor? primarySwatch,
- Color? scaffoldBackgroundColor,
- Color? secondaryHeaderColor,
- Color? shadowColor,
- Color? splashColor,
- Color? unselectedWidgetColor,
- String? fontFamily,
- List<
String> ? fontFamilyFallback, - String? package,
- IconThemeData? iconTheme,
- IconThemeData? primaryIconTheme,
- TextTheme? primaryTextTheme,
- TextTheme? textTheme,
- Typography? typography,
- ActionIconThemeData? actionIconTheme,
- Object? appBarTheme,
- BadgeThemeData? badgeTheme,
- MaterialBannerThemeData? bannerTheme,
- BottomAppBarThemeData? bottomAppBarTheme,
- BottomSheetThemeData? bottomSheetTheme,
- ButtonBarThemeData? buttonBarTheme,
- ButtonThemeData? buttonTheme,
- CardThemeData? cardTheme,
- CarouselViewThemeData? carouselViewTheme,
- CheckboxThemeData? checkboxTheme,
- ChipThemeData? chipTheme,
- DataTableThemeData? dataTableTheme,
- DatePickerThemeData? datePickerTheme,
- DialogThemeData? dialogTheme,
- DividerThemeData? dividerTheme,
- DrawerThemeData? drawerTheme,
- DropdownMenuThemeData? dropdownMenuTheme,
- ElevatedButtonThemeData? elevatedButtonTheme,
- ExpansionTileThemeData? expansionTileTheme,
- FilledButtonThemeData? filledButtonTheme,
- FloatingActionButtonThemeData? floatingActionButtonTheme,
- IconButtonThemeData? iconButtonTheme,
- ListTileThemeData? listTileTheme,
- OutlinedButtonThemeData? outlinedButtonTheme,
- PopupMenuThemeData? popupMenuTheme,
- ProgressIndicatorThemeData? progressIndicatorTheme,
- RadioThemeData? radioTheme,
- SearchBarThemeData? searchBarTheme,
- SearchViewThemeData? searchViewTheme,
- SegmentedButtonThemeData? segmentedButtonTheme,
- SliderThemeData? sliderTheme,
- SnackBarThemeData? snackBarTheme,
- SwitchThemeData? switchTheme,
- TabBarThemeData? tabBarTheme,
- TextButtonThemeData? textButtonTheme,
- TextSelectionThemeData? textSelectionTheme,
- TimePickerThemeData? timePickerTheme,
- ToggleButtonsThemeData? toggleButtonsTheme,
- TooltipThemeData? tooltipTheme,
Fluent2ThemeData constructor
Implementation
factory Fluent2ThemeData({
MixedFluentTextTheme? fluentTextTheme,
MixedFluentStrokeTheme? fluentStrokeTheme,
MixedFluentShadowTheme? fluentShadowTheme,
FluentColors? fluentBrandColors,
// For the sanity of the reader, make sure these properties are in the same
// order in every place that they are separated by section comments (e.g.
// GENERAL CONFIGURATION). Each section except for deprecations should be
// alphabetical by symbol name.
// GENERAL CONFIGURATION
Iterable<Adaptation<Object>>? adaptations,
bool? applyElevationOverlayColor,
NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
Iterable<ThemeExtension<dynamic>>? extensions,
Object? inputDecorationTheme,
MaterialTapTargetSize? materialTapTargetSize,
PageTransitionsTheme? pageTransitionsTheme,
TargetPlatform? platform,
ScrollbarThemeData? scrollbarTheme,
InteractiveInkFeatureFactory? splashFactory,
bool? useMaterial3,
VisualDensity? visualDensity,
// COLOR
// [colorScheme] is the preferred way to configure colors. The other color
// properties (as well as primarySwatch) will gradually be phased out, see
// https://github.com/flutter/flutter/issues/91772.
Brightness? brightness,
Color? canvasColor,
Color? cardColor,
ColorScheme? colorScheme,
Color? colorSchemeSeed,
Color? dialogBackgroundColor,
Color? disabledColor,
Color? dividerColor,
Color? focusColor,
Color? highlightColor,
Color? hintColor,
Color? hoverColor,
Color? indicatorColor,
Color? primaryColor,
Color? primaryColorDark,
Color? primaryColorLight,
MaterialColor? primarySwatch,
Color? scaffoldBackgroundColor,
Color? secondaryHeaderColor,
Color? shadowColor,
Color? splashColor,
Color? unselectedWidgetColor,
// TYPOGRAPHY & ICONOGRAPHY
String? fontFamily,
List<String>? fontFamilyFallback,
String? package,
IconThemeData? iconTheme,
IconThemeData? primaryIconTheme,
TextTheme? primaryTextTheme,
TextTheme? textTheme,
Typography? typography,
// COMPONENT THEMES
ActionIconThemeData? actionIconTheme,
Object? appBarTheme,
BadgeThemeData? badgeTheme,
MaterialBannerThemeData? bannerTheme,
BottomAppBarThemeData? bottomAppBarTheme,
BottomNavigationBarThemeData? bottomNavigationBarTheme,
BottomSheetThemeData? bottomSheetTheme,
// ignore: deprecated_member_use
ButtonBarThemeData? buttonBarTheme,
ButtonThemeData? buttonTheme,
CardThemeData? cardTheme,
CarouselViewThemeData? carouselViewTheme,
CheckboxThemeData? checkboxTheme,
ChipThemeData? chipTheme,
DataTableThemeData? dataTableTheme,
DatePickerThemeData? datePickerTheme,
DialogThemeData? dialogTheme,
DividerThemeData? dividerTheme,
DrawerThemeData? drawerTheme,
DropdownMenuThemeData? dropdownMenuTheme,
ElevatedButtonThemeData? elevatedButtonTheme,
ExpansionTileThemeData? expansionTileTheme,
FilledButtonThemeData? filledButtonTheme,
FloatingActionButtonThemeData? floatingActionButtonTheme,
IconButtonThemeData? iconButtonTheme,
ListTileThemeData? listTileTheme,
MenuBarThemeData? menuBarTheme,
MenuButtonThemeData? menuButtonTheme,
MenuThemeData? menuTheme,
NavigationBarThemeData? navigationBarTheme,
NavigationDrawerThemeData? navigationDrawerTheme,
NavigationRailThemeData? navigationRailTheme,
OutlinedButtonThemeData? outlinedButtonTheme,
PopupMenuThemeData? popupMenuTheme,
ProgressIndicatorThemeData? progressIndicatorTheme,
RadioThemeData? radioTheme,
SearchBarThemeData? searchBarTheme,
SearchViewThemeData? searchViewTheme,
SegmentedButtonThemeData? segmentedButtonTheme,
SliderThemeData? sliderTheme,
SnackBarThemeData? snackBarTheme,
SwitchThemeData? switchTheme,
TabBarThemeData? tabBarTheme,
TextButtonThemeData? textButtonTheme,
TextSelectionThemeData? textSelectionTheme,
TimePickerThemeData? timePickerTheme,
ToggleButtonsThemeData? toggleButtonsTheme,
TooltipThemeData? tooltipTheme,
}) {
// GENERAL CONFIGURATION
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
extensions ??= <ThemeExtension<dynamic>>[];
adaptations ??= <Adaptation<Object>>[];
if (inputDecorationTheme != null) {
if (inputDecorationTheme is InputDecorationTheme) {
inputDecorationTheme = inputDecorationTheme.data;
} else if (inputDecorationTheme is! InputDecorationThemeData) {
throw ArgumentError(
'inputDecorationTheme must be either a '
'InputDecorationThemeData or a InputDecorationTheme',
);
}
}
inputDecorationTheme ??= const InputDecorationThemeData();
platform ??= defaultTargetPlatform;
switch (platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
materialTapTargetSize ??= MaterialTapTargetSize.padded;
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
materialTapTargetSize ??= MaterialTapTargetSize.shrinkWrap;
}
pageTransitionsTheme ??= const PageTransitionsTheme();
scrollbarTheme ??= const ScrollbarThemeData();
visualDensity ??= VisualDensity.defaultDensityForPlatform(platform);
useMaterial3 ??= true;
final bool useInkSparkle = platform == TargetPlatform.android && !kIsWeb;
splashFactory ??= useMaterial3
? useInkSparkle
? InkSparkle.splashFactory
: InkRipple.splashFactory
: InkSplash.splashFactory;
// COLOR
assert(
colorScheme?.brightness == null ||
brightness == null ||
colorScheme!.brightness == brightness,
'ThemeData.brightness does not match ColorScheme.brightness. '
'Either override ColorScheme.brightness or ThemeData.brightness to '
'match the other.',
);
assert(colorSchemeSeed == null || colorScheme == null);
assert(colorSchemeSeed == null || primarySwatch == null);
assert(colorSchemeSeed == null || primaryColor == null);
final Brightness effectiveBrightness =
brightness ?? colorScheme?.brightness ?? Brightness.light;
final bool isDark = effectiveBrightness == Brightness.dark;
if (colorSchemeSeed != null || useMaterial3) {
if (colorSchemeSeed != null) {
colorScheme = ColorScheme.fromSeed(
seedColor: colorSchemeSeed,
brightness: effectiveBrightness,
);
}
colorScheme ??= isDark ? _colorSchemeDarkM3 : _colorSchemeLightM3;
// For surfaces that use primary color in light themes and surface color in dark
final Color primarySurfaceColor = isDark
? colorScheme.surface
: colorScheme.primary;
final Color onPrimarySurfaceColor = isDark
? colorScheme.onSurface
: colorScheme.onPrimary;
// Default some of the color settings to values from the color scheme
primaryColor ??= primarySurfaceColor;
// ignore: deprecated_member_use
canvasColor ??= colorScheme.background;
// ignore: deprecated_member_use
scaffoldBackgroundColor ??= colorScheme.background;
cardColor ??= colorScheme.surface;
dividerColor ??= colorScheme.outline;
// ignore: deprecated_member_use
dialogBackgroundColor ??= colorScheme.background;
indicatorColor ??= onPrimarySurfaceColor;
applyElevationOverlayColor ??= brightness == Brightness.dark;
}
applyElevationOverlayColor ??= false;
primarySwatch ??= Colors.blue;
primaryColor ??= isDark ? Colors.grey[900]! : primarySwatch;
final Brightness estimatedPrimaryColorBrightness =
ThemeData.estimateBrightnessForColor(primaryColor);
primaryColorLight ??= isDark ? Colors.grey[500]! : primarySwatch[100]!;
primaryColorDark ??= isDark ? Colors.black : primarySwatch[700]!;
final bool primaryIsDark =
estimatedPrimaryColorBrightness == Brightness.dark;
focusColor ??= isDark
? Colors.white.withAlpha((255 * 0.12).toInt())
: Colors.black.withAlpha((255 * 0.12).toInt());
hoverColor ??= isDark
? Colors.white.withAlpha((255 * 0.04).toInt())
: Colors.black.withAlpha((255 * 0.04).toInt());
shadowColor ??= Colors.black;
canvasColor ??= isDark ? Colors.grey[850]! : Colors.grey[50]!;
scaffoldBackgroundColor ??= canvasColor;
cardColor ??= isDark ? Colors.grey[800]! : Colors.white;
dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000);
// Create a ColorScheme that is backwards compatible as possible
// with the existing default ThemeData color values.
colorScheme ??= ColorScheme.fromSwatch(
primarySwatch: primarySwatch,
accentColor: isDark ? Colors.tealAccent[200]! : primarySwatch[500]!,
cardColor: cardColor,
backgroundColor: isDark ? Colors.grey[700]! : primarySwatch[200]!,
errorColor: Colors.red[700],
brightness: effectiveBrightness,
);
unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54;
// Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess.
secondaryHeaderColor ??= isDark ? Colors.grey[700]! : primarySwatch[50]!;
dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white;
indicatorColor ??= colorScheme.secondary == primaryColor
? Colors.white
: colorScheme.secondary;
hintColor ??= isDark
? Colors.white60
: Colors.black.withAlpha((255 * 0.6).toInt());
// The default [buttonTheme] is here because it doesn't use the defaults for
// [disabledColor], [highlightColor], and [splashColor].
buttonTheme ??= ButtonThemeData(
colorScheme: colorScheme,
buttonColor: isDark ? primarySwatch[600]! : Colors.grey[300]!,
disabledColor: disabledColor,
focusColor: focusColor,
hoverColor: hoverColor,
highlightColor: highlightColor,
splashColor: splashColor,
materialTapTargetSize: materialTapTargetSize,
);
disabledColor ??= isDark ? Colors.white38 : Colors.black38;
highlightColor ??= isDark
? _kDarkThemeHighlightColor
: _kLightThemeHighlightColor;
splashColor ??= isDark ? _kDarkThemeSplashColor : _kLightThemeSplashColor;
// TYPOGRAPHY & ICONOGRAPHY
typography ??= useMaterial3
? Typography.material2021(platform: platform, colorScheme: colorScheme)
: Typography.material2014(platform: platform);
TextTheme defaultTextTheme = isDark ? typography.white : typography.black;
TextTheme defaultPrimaryTextTheme = primaryIsDark
? typography.white
: typography.black;
if (fontFamily != null) {
defaultTextTheme = defaultTextTheme.apply(fontFamily: fontFamily);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(
fontFamily: fontFamily,
);
}
if (fontFamilyFallback != null) {
defaultTextTheme = defaultTextTheme.apply(
fontFamilyFallback: fontFamilyFallback,
);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(
fontFamilyFallback: fontFamilyFallback,
);
}
if (package != null) {
defaultTextTheme = defaultTextTheme.apply(package: package);
defaultPrimaryTextTheme = defaultPrimaryTextTheme.apply(package: package);
}
textTheme = defaultTextTheme.merge(textTheme);
primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
iconTheme ??= isDark
? IconThemeData(color: kDefaultIconLightColor)
: IconThemeData(color: kDefaultIconDarkColor);
primaryIconTheme ??= primaryIsDark
? const IconThemeData(color: Colors.white)
: const IconThemeData(color: Colors.black);
// COMPONENT THEMES
if (appBarTheme != null) {
if (appBarTheme is AppBarTheme) {
appBarTheme = appBarTheme.data;
} else if (appBarTheme is! AppBarThemeData) {
throw ArgumentError(
'appBarTheme must be either a AppBarThemeData or a AppBarTheme',
);
}
}
appBarTheme ??= const AppBarThemeData();
badgeTheme ??= const BadgeThemeData();
bannerTheme ??= const MaterialBannerThemeData();
bottomAppBarTheme ??= const BottomAppBarThemeData();
bottomNavigationBarTheme ??= const BottomNavigationBarThemeData();
bottomSheetTheme ??= const BottomSheetThemeData();
// ignore: deprecated_member_use
buttonBarTheme ??= const ButtonBarThemeData();
cardTheme ??= const CardThemeData();
carouselViewTheme ??= const CarouselViewThemeData();
checkboxTheme ??= const CheckboxThemeData();
chipTheme ??= const ChipThemeData();
dataTableTheme ??= const DataTableThemeData();
datePickerTheme ??= const DatePickerThemeData();
dialogTheme ??= const DialogThemeData();
dividerTheme ??= const DividerThemeData();
drawerTheme ??= const DrawerThemeData();
dropdownMenuTheme ??= const DropdownMenuThemeData();
elevatedButtonTheme ??= const ElevatedButtonThemeData();
expansionTileTheme ??= const ExpansionTileThemeData();
filledButtonTheme ??= const FilledButtonThemeData();
floatingActionButtonTheme ??= const FloatingActionButtonThemeData();
iconButtonTheme ??= const IconButtonThemeData();
listTileTheme ??= const ListTileThemeData();
menuBarTheme ??= const MenuBarThemeData();
menuButtonTheme ??= const MenuButtonThemeData();
menuTheme ??= const MenuThemeData();
navigationBarTheme ??= const NavigationBarThemeData();
navigationDrawerTheme ??= const NavigationDrawerThemeData();
navigationRailTheme ??= const NavigationRailThemeData();
outlinedButtonTheme ??= const OutlinedButtonThemeData();
popupMenuTheme ??= const PopupMenuThemeData();
progressIndicatorTheme ??= const ProgressIndicatorThemeData();
radioTheme ??= const RadioThemeData();
searchBarTheme ??= const SearchBarThemeData();
searchViewTheme ??= const SearchViewThemeData();
segmentedButtonTheme ??= const SegmentedButtonThemeData();
sliderTheme ??= const SliderThemeData();
snackBarTheme ??= const SnackBarThemeData();
switchTheme ??= const SwitchThemeData();
tabBarTheme ??= const TabBarThemeData();
textButtonTheme ??= const TextButtonThemeData();
textSelectionTheme ??= const TextSelectionThemeData();
timePickerTheme ??= const TimePickerThemeData();
toggleButtonsTheme ??= const ToggleButtonsThemeData();
tooltipTheme ??= const TooltipThemeData();
return Fluent2ThemeData.raw(
fluentTextTheme: fluentTextTheme,
fluentStrokeTheme: fluentStrokeTheme,
fluentShadowTheme: fluentShadowTheme,
fluentBrandColors: fluentBrandColors,
adaptationMap: _createAdaptationMap(adaptations),
// FROM HERE TO BOTTOM IT JUST COPY-AND-PASTE FROM MATERIALTHEME
// For the sanity of the reader, make sure these properties are in the same
// order in every place that they are separated by section comments (e.g.
// GENERAL CONFIGURATION). Each section except for deprecations should be
// alphabetical by symbol name.
// GENERAL CONFIGURATION
applyElevationOverlayColor: applyElevationOverlayColor,
// ⚠️ cupertinoOverrideTheme: cupertinoOverrideTheme,
extensions: {},
// ⚠️_themeExtensionIterableToMap(extensions),
inputDecorationTheme: inputDecorationTheme as InputDecorationThemeData,
materialTapTargetSize: materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme,
platform: platform,
scrollbarTheme: scrollbarTheme,
splashFactory: splashFactory,
useMaterial3: useMaterial3,
visualDensity: visualDensity,
// COLOR
canvasColor: canvasColor,
cardColor: cardColor,
colorScheme: colorScheme,
dialogBackgroundColor: dialogBackgroundColor,
disabledColor: disabledColor,
dividerColor: dividerColor,
focusColor: focusColor,
highlightColor: highlightColor,
hintColor: hintColor,
hoverColor: hoverColor,
indicatorColor: indicatorColor,
primaryColor: primaryColor,
primaryColorDark: primaryColorDark,
primaryColorLight: primaryColorLight,
scaffoldBackgroundColor: scaffoldBackgroundColor,
secondaryHeaderColor: secondaryHeaderColor,
shadowColor: shadowColor,
splashColor: splashColor,
unselectedWidgetColor: unselectedWidgetColor,
// TYPOGRAPHY & ICONOGRAPHY
iconTheme: iconTheme,
primaryTextTheme: primaryTextTheme,
textTheme: textTheme,
typography: typography,
primaryIconTheme: primaryIconTheme,
// COMPONENT THEMES
actionIconTheme: actionIconTheme,
appBarTheme: appBarTheme as AppBarThemeData,
badgeTheme: badgeTheme,
bannerTheme: bannerTheme,
bottomAppBarTheme: bottomAppBarTheme,
bottomNavigationBarTheme: bottomNavigationBarTheme,
bottomSheetTheme: bottomSheetTheme,
buttonBarTheme: buttonBarTheme,
buttonTheme: buttonTheme,
cardTheme: cardTheme,
carouselViewTheme: carouselViewTheme,
checkboxTheme: checkboxTheme,
chipTheme: chipTheme,
dataTableTheme: dataTableTheme,
datePickerTheme: datePickerTheme,
dialogTheme: dialogTheme,
dividerTheme: dividerTheme,
drawerTheme: drawerTheme,
dropdownMenuTheme: dropdownMenuTheme,
elevatedButtonTheme: elevatedButtonTheme,
expansionTileTheme: expansionTileTheme,
filledButtonTheme: filledButtonTheme,
floatingActionButtonTheme: floatingActionButtonTheme,
iconButtonTheme: iconButtonTheme,
listTileTheme: listTileTheme,
menuBarTheme: menuBarTheme,
menuButtonTheme: menuButtonTheme,
menuTheme: menuTheme,
navigationBarTheme: navigationBarTheme,
navigationDrawerTheme: navigationDrawerTheme,
navigationRailTheme: navigationRailTheme,
outlinedButtonTheme: outlinedButtonTheme,
popupMenuTheme: popupMenuTheme,
progressIndicatorTheme: progressIndicatorTheme,
radioTheme: radioTheme,
searchBarTheme: searchBarTheme,
searchViewTheme: searchViewTheme,
segmentedButtonTheme: segmentedButtonTheme,
sliderTheme: sliderTheme,
snackBarTheme: snackBarTheme,
switchTheme: switchTheme,
tabBarTheme: tabBarTheme,
textButtonTheme: textButtonTheme,
textSelectionTheme: textSelectionTheme,
timePickerTheme: timePickerTheme,
toggleButtonsTheme: toggleButtonsTheme,
tooltipTheme: tooltipTheme,
);
}