Skip to content

Instantly share code, notes, and snippets.

@mortezanazari-hub
Created January 23, 2025 12:44
Show Gist options
  • Select an option

  • Save mortezanazari-hub/ab2d23f60c7f24251d7e1b83910cd65a to your computer and use it in GitHub Desktop.

Select an option

Save mortezanazari-hub/ab2d23f60c7f24251d7e1b83910cd65a to your computer and use it in GitHub Desktop.
/// {@template app_input_theme}
/// کلاس تم که پیکربندی [AppTextField] را فراهم می‌کند.
/// Theme class which provides configuration of [AppTextField]
/// {@endtemplate}
class AppInputTheme extends ThemeExtension<AppInputTheme> {
/// {@macro app_input_theme}
const AppInputTheme({
required this.defaultText,
required this.focusedOnBrand,
required this.focusedTextDefault,
required this.errorTextDefault,
required this.successTextDefault,
required this.disabledText,
required this.borderDefault,
required this.borderHover,
required this.borderFocused,
required this.borderError,
required this.borderSuccess,
required this.borderDisabled,
required this.defaultColor,
required this.disabledColor,
});
/// {@macro app_input_theme}
factory AppInputTheme.light() {
return AppInputTheme(
defaultText: AppColors.grayLight.shade400,
focusedOnBrand: AppColors.brand.shade500,
focusedTextDefault: AppColors.grayLight.shade600,
errorTextDefault: AppColors.error.shade400,
successTextDefault: AppColors.success.shade400,
disabledText: AppColors.grayLight[250]!,
borderDefault: AppColors.grayLight[250]!,
borderHover: AppColors.grayLight.shade300,
borderFocused: AppColors.brand.shade500,
borderError: AppColors.error.shade400,
borderSuccess: AppColors.success.shade400,
borderDisabled: AppColors.grayLight.shade200,
defaultColor: AppColors.white,
disabledColor: AppColors.grayLight.shade100,
);
}
/// رنگ متن پیش‌فرض.
/// The default text color.
final Color defaultText;
/// رنگ متن هنگامی که روی برند فوکوس باشد.
/// The text color when focused on brand.
final Color focusedOnBrand;
/// رنگ متن هنگامی که فوکوس باشد.
/// The text color when focused.
final Color focusedTextDefault;
/// رنگ متن هنگام خطا.
/// The text color when error.
final Color errorTextDefault;
/// رنگ متن هنگام موفقیت.
/// The text color when success.
final Color successTextDefault;
/// رنگ متن هنگام غیرفعال بودن.
/// The text color when disabled.
final Color disabledText;
/// رنگ پیش‌فرض حاشیه.
/// The default border color.
final Color borderDefault;
/// رنگ حاشیه هنگام قرار گرفتن ماوس روی آن (Hover).
/// The border color when hovered.
final Color borderHover;
/// رنگ حاشیه هنگام فوکوس.
/// The border color when focused.
final Color borderFocused;
/// رنگ حاشیه هنگام خطا.
/// The border color when error.
final Color borderError;
/// رنگ حاشیه هنگام موفقیت.
/// The border color when success.
final Color borderSuccess;
/// رنگ حاشیه هنگام غیرفعال بودن.
/// The border color when disabled.
final Color borderDisabled;
/// رنگ پیش‌فرض.
/// The default color.
final Color defaultColor;
/// رنگ غیرفعال.
/// The disabled color.
final Color disabledColor;
@override
ThemeExtension<AppInputTheme> copyWith({
Color? defaultText,
Color? focusedOnBrand,
Color? focusedTextDefault,
Color? errorTextDefault,
Color? successTextDefault,
Color? disabledText,
Color? borderDefault,
Color? borderHover,
Color? borderFocused,
Color? borderError,
Color? borderSuccess,
Color? borderDisabled,
Color? defaultColor,
Color? disabledColor,
}) {
return AppInputTheme(
defaultText: defaultText ?? this.defaultText,
focusedOnBrand: focusedOnBrand ?? this.focusedOnBrand,
focusedTextDefault: focusedTextDefault ?? this.focusedTextDefault,
errorTextDefault: errorTextDefault ?? this.errorTextDefault,
successTextDefault: successTextDefault ?? this.successTextDefault,
disabledText: disabledText ?? this.disabledText,
borderDefault: borderDefault ?? this.borderDefault,
borderHover: borderHover ?? this.borderHover,
borderFocused: borderFocused ?? this.borderFocused,
borderError: borderError ?? this.borderError,
borderSuccess: borderSuccess ?? this.borderSuccess,
borderDisabled: borderDisabled ?? this.borderDisabled,
defaultColor: defaultColor ?? this.defaultColor,
disabledColor: disabledColor ?? this.disabledColor,
);
}
@override
ThemeExtension<AppInputTheme> lerp(
covariant ThemeExtension<AppInputTheme>? other,
double t,
) {
if (other is! AppInputTheme) {
return this;
}
return AppInputTheme(
defaultText: Color.lerp(defaultText, other.defaultText, t)!,
focusedOnBrand: Color.lerp(focusedOnBrand, other.focusedOnBrand, t)!,
focusedTextDefault: Color.lerp(
focusedTextDefault,
other.focusedTextDefault,
t,
)!,
errorTextDefault: Color.lerp(
errorTextDefault,
other.errorTextDefault,
t,
)!,
successTextDefault: Color.lerp(
successTextDefault,
other.successTextDefault,
t,
)!,
disabledText: Color.lerp(disabledText, other.disabledText, t)!,
borderDefault: Color.lerp(borderDefault, other.borderDefault, t)!,
borderHover: Color.lerp(borderHover, other.borderHover, t)!,
borderFocused: Color.lerp(borderFocused, other.borderFocused, t)!,
borderError: Color.lerp(borderError, other.borderError, t)!,
borderSuccess: Color.lerp(borderSuccess, other.borderSuccess, t)!,
borderDisabled: Color.lerp(borderDisabled, other.borderDisabled, t)!,
defaultColor: Color.lerp(defaultColor, other.defaultColor, t)!,
disabledColor: Color.lerp(disabledColor, other.disabledColor, t)!,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment