67 lines
1.7 KiB
Dart
67 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'app_colors_base.dart';
|
|
|
|
@immutable
|
|
class AppThemeExtension extends ThemeExtension<AppThemeExtension> {
|
|
final Color success;
|
|
final Color warning;
|
|
final Color danger;
|
|
final Color textSecondary;
|
|
|
|
const AppThemeExtension({
|
|
required this.success,
|
|
required this.warning,
|
|
required this.danger,
|
|
required this.textSecondary,
|
|
});
|
|
|
|
// 工厂方法,根据 AppColorsBase 创建
|
|
factory AppThemeExtension.fromColors(AppColorsBase colors) {
|
|
return AppThemeExtension(
|
|
success: colors.success,
|
|
warning: colors.warning,
|
|
danger: colors.danger,
|
|
textSecondary: colors.textSecondary,
|
|
);
|
|
}
|
|
|
|
@override
|
|
ThemeExtension<AppThemeExtension> copyWith({
|
|
Color? success,
|
|
Color? warning,
|
|
Color? danger,
|
|
Color? textSecondary,
|
|
}) {
|
|
return AppThemeExtension(
|
|
success: success ?? this.success,
|
|
warning: warning ?? this.warning,
|
|
danger: danger ?? this.danger,
|
|
textSecondary: textSecondary ?? this.textSecondary,
|
|
);
|
|
}
|
|
|
|
@override
|
|
AppThemeExtension lerp(AppThemeExtension? other, double t) {
|
|
if (other == null) return this;
|
|
return AppThemeExtension(
|
|
success: Color.lerp(success, other.success, t)!,
|
|
warning: Color.lerp(warning, other.warning, t)!,
|
|
danger: Color.lerp(danger, other.danger, t)!,
|
|
textSecondary: Color.lerp(textSecondary, other.textSecondary, t)!,
|
|
);
|
|
}
|
|
}
|
|
|
|
extension AppThemeExt on BuildContext {
|
|
AppThemeExtension get themeEx => Theme.of(this).extension<AppThemeExtension>()!;
|
|
|
|
Color get success => themeEx.success;
|
|
|
|
Color get warning => themeEx.warning;
|
|
|
|
Color get danger => themeEx.danger;
|
|
|
|
Color get textSecondary => themeEx.textSecondary;
|
|
}
|