M3 Overhaul

This commit is contained in:
2026-03-06 20:03:32 +08:00
parent 82fe619f22
commit 73dc735cce
32 changed files with 1940 additions and 682 deletions
+38 -37
View File
@@ -1,22 +1,34 @@
import 'package:flutter/material.dart';
/// M3 Expressive surface tokens.
///
/// Cards now use **tonal elevation** (color tints) instead of drop-shadows.
/// Large containers adopt the M3 standard 28 dp corner radius; compact items
/// use 16 dp; small chips/badges use 12 dp.
@immutable
class AppSurfaces extends ThemeExtension<AppSurfaces> {
const AppSurfaces({
required this.cardRadius,
required this.compactCardRadius,
required this.containerRadius,
required this.dialogRadius,
required this.cardElevation,
required this.cardShadowColor,
required this.compactShadowColor,
required this.chipRadius,
});
/// Standard card radius 16 dp (M3 medium shape).
final double cardRadius;
/// Compact card radius for dense list tiles 12 dp.
final double compactCardRadius;
/// Large container radius 28 dp (M3 Expressive).
final double containerRadius;
/// Dialog / bottom-sheet radius 28 dp.
final double dialogRadius;
final double cardElevation;
final Color cardShadowColor;
final Color compactShadowColor;
/// Chip / badge radius 12 dp.
final double chipRadius;
// convenience shapes
RoundedRectangleBorder get standardShape =>
@@ -24,6 +36,9 @@ class AppSurfaces extends ThemeExtension<AppSurfaces> {
RoundedRectangleBorder get compactShape => RoundedRectangleBorder(
borderRadius: BorderRadius.circular(compactCardRadius),
);
RoundedRectangleBorder get containerShape => RoundedRectangleBorder(
borderRadius: BorderRadius.circular(containerRadius),
);
RoundedRectangleBorder get dialogShape =>
RoundedRectangleBorder(borderRadius: BorderRadius.circular(dialogRadius));
@@ -33,10 +48,9 @@ class AppSurfaces extends ThemeExtension<AppSurfaces> {
const AppSurfaces(
cardRadius: 16,
compactCardRadius: 12,
dialogRadius: 20,
cardElevation: 3,
cardShadowColor: Color.fromRGBO(0, 0, 0, 0.12),
compactShadowColor: Color.fromRGBO(0, 0, 0, 0.08),
containerRadius: 28,
dialogRadius: 28,
chipRadius: 12,
);
}
@@ -44,18 +58,16 @@ class AppSurfaces extends ThemeExtension<AppSurfaces> {
AppSurfaces copyWith({
double? cardRadius,
double? compactCardRadius,
double? containerRadius,
double? dialogRadius,
double? cardElevation,
Color? cardShadowColor,
Color? compactShadowColor,
double? chipRadius,
}) {
return AppSurfaces(
cardRadius: cardRadius ?? this.cardRadius,
compactCardRadius: compactCardRadius ?? this.compactCardRadius,
containerRadius: containerRadius ?? this.containerRadius,
dialogRadius: dialogRadius ?? this.dialogRadius,
cardElevation: cardElevation ?? this.cardElevation,
cardShadowColor: cardShadowColor ?? this.cardShadowColor,
compactShadowColor: compactShadowColor ?? this.compactShadowColor,
chipRadius: chipRadius ?? this.chipRadius,
);
}
@@ -63,28 +75,17 @@ class AppSurfaces extends ThemeExtension<AppSurfaces> {
AppSurfaces lerp(ThemeExtension<AppSurfaces>? other, double t) {
if (other is! AppSurfaces) return this;
return AppSurfaces(
cardRadius: lerpDouble(cardRadius, other.cardRadius, t) ?? cardRadius,
compactCardRadius:
lerpDouble(compactCardRadius, other.compactCardRadius, t) ??
compactCardRadius,
dialogRadius:
lerpDouble(dialogRadius, other.dialogRadius, t) ?? dialogRadius,
cardElevation:
lerpDouble(cardElevation, other.cardElevation, t) ?? cardElevation,
cardShadowColor:
Color.lerp(cardShadowColor, other.cardShadowColor, t) ??
cardShadowColor,
compactShadowColor:
Color.lerp(compactShadowColor, other.compactShadowColor, t) ??
compactShadowColor,
cardRadius: _lerpDouble(cardRadius, other.cardRadius, t),
compactCardRadius: _lerpDouble(
compactCardRadius,
other.compactCardRadius,
t,
),
containerRadius: _lerpDouble(containerRadius, other.containerRadius, t),
dialogRadius: _lerpDouble(dialogRadius, other.dialogRadius, t),
chipRadius: _lerpDouble(chipRadius, other.chipRadius, t),
);
}
}
// Helper because dart:ui lerpDouble isn't exported here
double? lerpDouble(num? a, num? b, double t) {
if (a == null && b == null) return null;
a = a ?? 0;
b = b ?? 0;
return a + (b - a) * t;
}
double _lerpDouble(double a, double b, double t) => a + (b - a) * t;