8ca3d3e467
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
158 lines
5.8 KiB
Dart
158 lines
5.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'glass_theme.dart';
|
|
|
|
const Color _clear = Color(0x00000000);
|
|
|
|
// Kept per colour: a tab indicator compares by identity, so a fresh one
|
|
// would make a rebuilt theme unequal to the last
|
|
// (test/perf/design_bench_test.dart).
|
|
final Map<(Color, Color, Color), Decoration> _tabIndicators = {};
|
|
final Map<(Color, Color), WidgetStateProperty<Color?>> _segmentFills = {};
|
|
|
|
/// [base] with Glass's controls: pill buttons without elevation, glass
|
|
/// menus and fields in the design's radii, pill chips with a glass edge,
|
|
/// a frosted segmented button, a soft tab slab and thin progress.
|
|
ThemeData glassControls(ThemeData base, GlassSurfaces surfaces) {
|
|
final scheme = base.colorScheme;
|
|
final style = surfaces.style;
|
|
ButtonStyle flatter(ButtonStyle? s) => (s ?? const ButtonStyle()).copyWith(
|
|
elevation: const WidgetStatePropertyAll(0),
|
|
shadowColor: const WidgetStatePropertyAll(_clear),
|
|
);
|
|
final menu = MenuStyle(
|
|
backgroundColor: WidgetStatePropertyAll(surfaces.floating),
|
|
elevation: const WidgetStatePropertyAll(6),
|
|
shadowColor: WidgetStatePropertyAll(style.shadow),
|
|
surfaceTintColor: const WidgetStatePropertyAll(_clear),
|
|
shape: WidgetStatePropertyAll(surfaces.edge(GlassRadii.card)),
|
|
padding: const WidgetStatePropertyAll(EdgeInsets.all(6)),
|
|
);
|
|
const itemShape = RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(GlassRadii.small)),
|
|
);
|
|
const fieldCorners = BorderRadius.all(Radius.circular(GlassRadii.field));
|
|
final pill = surfaces.edge(GlassRadii.card);
|
|
return base.copyWith(
|
|
menuTheme: MenuThemeData(style: menu),
|
|
dropdownMenuTheme: DropdownMenuThemeData(menuStyle: menu),
|
|
menuButtonTheme: MenuButtonThemeData(
|
|
style: MenuItemButton.styleFrom(shape: itemShape),
|
|
),
|
|
filledButtonTheme: FilledButtonThemeData(
|
|
style: flatter(base.filledButtonTheme.style),
|
|
),
|
|
elevatedButtonTheme: ElevatedButtonThemeData(
|
|
style: flatter(base.elevatedButtonTheme.style).copyWith(
|
|
backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerHigh),
|
|
shape: WidgetStatePropertyAll(pill),
|
|
),
|
|
),
|
|
outlinedButtonTheme: OutlinedButtonThemeData(
|
|
style: flatter(base.outlinedButtonTheme.style).copyWith(
|
|
side: WidgetStatePropertyAll(BorderSide(color: scheme.outline)),
|
|
),
|
|
),
|
|
textButtonTheme: TextButtonThemeData(
|
|
style: flatter(base.textButtonTheme.style),
|
|
),
|
|
segmentedButtonTheme: SegmentedButtonThemeData(
|
|
style: flatter(base.segmentedButtonTheme.style).copyWith(
|
|
side: WidgetStatePropertyAll(BorderSide(color: style.edge)),
|
|
backgroundColor:
|
|
_segmentFills[(
|
|
scheme.secondaryContainer,
|
|
scheme.surfaceContainerLow,
|
|
)] ??= WidgetStateProperty.resolveWith(
|
|
(states) => states.contains(WidgetState.selected)
|
|
? scheme.secondaryContainer
|
|
: scheme.surfaceContainerLow,
|
|
),
|
|
),
|
|
),
|
|
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
|
elevation: 4,
|
|
focusElevation: 4,
|
|
hoverElevation: 6,
|
|
highlightElevation: 6,
|
|
backgroundColor: style.solid,
|
|
foregroundColor: scheme.primary,
|
|
shape: surfaces.edge(GlassRadii.card),
|
|
),
|
|
chipTheme: ChipThemeData(
|
|
backgroundColor: scheme.surfaceContainerLow,
|
|
selectedColor: scheme.secondaryContainer,
|
|
shape: pill,
|
|
side: BorderSide.none,
|
|
elevation: 0,
|
|
pressElevation: 0,
|
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
|
),
|
|
// Only the base border: a field that sets `InputBorder.none` (the
|
|
// composer, whose frame is its pill) keeps none in every state.
|
|
inputDecorationTheme: InputDecorationTheme(
|
|
filled: false,
|
|
border: OutlineInputBorder(
|
|
borderRadius: fieldCorners,
|
|
borderSide: BorderSide(color: scheme.outline),
|
|
),
|
|
),
|
|
searchBarTheme: SearchBarThemeData(
|
|
elevation: const WidgetStatePropertyAll(0),
|
|
shape: WidgetStatePropertyAll(pill),
|
|
backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerHigh),
|
|
surfaceTintColor: const WidgetStatePropertyAll(_clear),
|
|
padding: const WidgetStatePropertyAll(
|
|
EdgeInsets.symmetric(horizontal: 14),
|
|
),
|
|
),
|
|
listTileTheme: const ListTileThemeData(shape: itemShape),
|
|
expansionTileTheme: const ExpansionTileThemeData(
|
|
shape: Border(),
|
|
collapsedShape: Border(),
|
|
),
|
|
tabBarTheme: TabBarThemeData(
|
|
dividerColor: _clear,
|
|
labelColor: scheme.onSurface,
|
|
unselectedLabelColor: scheme.onSurfaceVariant,
|
|
indicatorSize: TabBarIndicatorSize.tab,
|
|
indicator: _tabIndicators[(
|
|
scheme.secondaryContainer,
|
|
style.highlight,
|
|
style.edge,
|
|
)] ??= ShapeDecoration(
|
|
color: scheme.secondaryContainer,
|
|
shape: surfaces.edge(GlassRadii.small),
|
|
),
|
|
splashBorderRadius: const BorderRadius.all(
|
|
Radius.circular(GlassRadii.small),
|
|
),
|
|
),
|
|
checkboxTheme: const CheckboxThemeData(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(5)),
|
|
),
|
|
),
|
|
sliderTheme: SliderThemeData(
|
|
trackHeight: 4,
|
|
inactiveTrackColor: scheme.surfaceContainerHighest,
|
|
),
|
|
badgeTheme: BadgeThemeData(
|
|
backgroundColor: scheme.primary,
|
|
textColor: scheme.onPrimary,
|
|
padding: const EdgeInsets.symmetric(horizontal: 5),
|
|
),
|
|
progressIndicatorTheme: ProgressIndicatorThemeData(
|
|
color: scheme.primary,
|
|
linearTrackColor: scheme.surfaceContainerHighest,
|
|
circularTrackColor: _clear,
|
|
linearMinHeight: 3,
|
|
borderRadius: const BorderRadius.all(Radius.circular(2)),
|
|
),
|
|
scrollbarTheme: const ScrollbarThemeData(
|
|
radius: Radius.circular(4),
|
|
thickness: WidgetStatePropertyAll(6),
|
|
),
|
|
);
|
|
}
|