TInputFieldTheme.defaultTheme constructor
TInputFieldTheme.defaultTheme(
- ColorScheme colors, {
- TInputDecorationType decorationType = TInputDecorationType.box,
Implementation
factory TInputFieldTheme.defaultTheme(ColorScheme colors, {TInputDecorationType decorationType = TInputDecorationType.box}) {
final color = WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.error)) return colors.error;
if (states.contains(WidgetState.focused)) return colors.primary;
if (states.contains(WidgetState.disabled)) return colors.outlineVariant;
return colors.outline;
});
final backgroundColor = WidgetStateProperty.resolveWith((states) {
if (decorationType == TInputDecorationType.filled) {
return states.contains(WidgetState.disabled) ? colors.surfaceDim.withAlpha(50) : colors.surfaceContainer;
}
return states.contains(WidgetState.disabled) ? colors.surfaceDim.withAlpha(50) : colors.surface;
});
final borderColor = WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.error)) return colors.error;
if (states.contains(WidgetState.focused)) return colors.primary;
if (states.contains(WidgetState.disabled)) return colors.outlineVariant;
return colors.outline;
});
final labelStyle = WidgetStateProperty.resolveWith((states) {
final isDisabled = states.contains(WidgetState.disabled);
return TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w500,
color: isDisabled ? colors.onSurfaceVariant.withAlpha(100) : colors.onSurfaceVariant,
);
});
final helperTextStyle = WidgetStateProperty.all(
TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w300,
color: colors.onSurfaceVariant.withAlpha(200),
),
);
final errorTextStyle = WidgetStateProperty.all(TextStyle(fontSize: 12.0, color: colors.error));
final tagStyle = WidgetStateProperty.all(TextStyle(fontSize: 11.0, fontWeight: FontWeight.w300, color: colors.onSurfaceVariant));
final borderWidth = WidgetStateProperty.resolveWith((states) => states.contains(WidgetState.focused) ? 2.0 : 1.0);
final borderRadius = WidgetStateProperty.resolveWith((states) {
return switch (decorationType) {
TInputDecorationType.outline => 12.0,
TInputDecorationType.filled => 8.0,
TInputDecorationType.underline => 0.0,
TInputDecorationType.none => 0.0,
TInputDecorationType.box => 6.0,
};
});
return TInputFieldTheme(
size: TInputSize.md,
decorationType: decorationType,
borderRadius: borderRadius,
borderWidth: borderWidth,
color: color,
backgroundColor: backgroundColor,
borderColor: borderColor,
labelStyle: labelStyle,
helperTextStyle: helperTextStyle,
errorTextStyle: errorTextStyle,
tagStyle: tagStyle,
decoration: _createDecoration(decorationType, borderWidth, borderRadius, backgroundColor, borderColor),
labelBuilder: _createLabelBuilder(labelStyle, tagStyle, errorTextStyle, backgroundColor),
helperTextBuilder: _createHelperTextBuilder(helperTextStyle),
errorsBuilder: _createErrorsBuilder(errorTextStyle),
);
}