withDefaults method
FormTheme
withDefaults({
- FormTheme? inputTheme,
- required TextTheme textInfo,
- required ColorScheme colorInfo,
Implementation
FormTheme withDefaults({
FormTheme? inputTheme,
required TextTheme textInfo,
required ColorScheme colorInfo,
}) {
// This is the main color scheme.
final passColorScheme = colorScheme ??
FieldColorScheme(
backgroundColor: colorInfo.primaryContainer,
borderColor: colorInfo.tertiary,
borderSize: 1,
borderRadius: BorderRadius.all(Radius.circular(8)),
textColor: colorInfo.primary,
hintTextColor: colorInfo.secondary,
titleColor: colorInfo.primary,
descriptionColor: colorInfo.primary,
textBackgroundColor: colorInfo.secondaryContainer,
iconColor: colorInfo.tertiary,
);
// This is the error color state.
final passErrorColorScheme = errorColorScheme ??
FieldColorScheme(
backgroundColor: colorInfo.errorContainer,
borderColor: colorInfo.error,
borderSize: 1,
borderRadius: BorderRadius.all(Radius.circular(8)),
textColor: colorInfo.primary,
hintTextColor: colorInfo.secondary,
titleColor: colorInfo.error,
descriptionColor: colorInfo.primary,
textBackgroundColor: colorInfo.secondaryContainer,
iconColor: colorInfo.error,
);
// This is the color scheme for disabled fields.
final passDisabledColorScheme = errorColorScheme ??
FieldColorScheme(
backgroundColor: colorInfo.tertiaryContainer,
borderColor: colorInfo.primaryContainer,
borderSize: 1,
borderRadius: BorderRadius.all(Radius.circular(8)),
textColor: colorInfo.primary,
hintTextColor: colorInfo.secondary,
titleColor: colorInfo.primary,
descriptionColor: colorInfo.primary,
textBackgroundColor: colorInfo.secondaryContainer,
iconColor: colorInfo.primary,
);
// This is the color scheme for selected elements.
final passSelectedColorScheme = colorScheme ??
FieldColorScheme(
backgroundColor: colorInfo.tertiaryContainer,
borderColor: colorInfo.primary,
borderSize: 1,
borderRadius: BorderRadius.all(Radius.circular(8)),
textColor: colorInfo.primary,
hintTextColor: colorInfo.secondary,
titleColor: colorInfo.primary,
descriptionColor: colorInfo.primary,
textBackgroundColor: colorInfo.secondaryContainer,
iconColor: colorInfo.tertiary,
);
// This is the color scheme for fields which are currently active.
final passActiveColorScheme = colorScheme ??
FieldColorScheme(
backgroundColor: colorInfo.primaryContainer,
borderColor: colorInfo.secondary,
borderSize: 1,
borderRadius: BorderRadius.all(Radius.circular(8)),
textColor: colorInfo.primary,
hintTextColor: colorInfo.secondary,
titleColor: colorInfo.primary,
descriptionColor: colorInfo.primary,
textBackgroundColor: colorInfo.secondaryContainer,
iconColor: colorInfo.tertiary,
);
// Create some default text Styles in case we didn't define anything
final passTitleTextStyle = titleStyle ??
textInfo.titleMedium ??
TextStyle(fontSize: 20, fontWeight: FontWeight.bold);
final passDescriptionTextStyle = descriptionStyle ??
textInfo.bodySmall ??
TextStyle(
fontSize: 12,
);
final passHintTextStyle = hintTextStyle ??
textInfo.bodyMedium ??
TextStyle(
fontSize: 12,
);
final passChipTextStyle = chipTextStyle ??
textInfo.bodySmall ??
TextStyle(
fontSize: 12,
);
FormTheme outputTheme = FormTheme(
colorScheme: passColorScheme,
errorColorScheme: passErrorColorScheme,
disabledColorScheme: passDisabledColorScheme,
selectedColorScheme: passSelectedColorScheme,
activeColorScheme: passActiveColorScheme,
titleStyle: passTitleTextStyle,
descriptionStyle: passDescriptionTextStyle,
hintTextStyle: passHintTextStyle,
chipTextStyle: passChipTextStyle,
);
if (inputTheme != null) {
return outputTheme.copyWith(theme: inputTheme);
}
return outputTheme;
}