5fc650211e
Paper's theme joins the cached builder; AppDesignTokens and ReadingType compare every new token by value, and Paper's tab indicator and switch outline resolver are kept per colour so a rebuilt Paper theme equals the last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
174 lines
6.7 KiB
Dart
174 lines
6.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'paper_theme.dart';
|
|
|
|
const Color _clear = Color(0x00000000);
|
|
|
|
// Kept per colour: a tab indicator and a resolver compare by identity, so
|
|
// fresh ones would make a rebuilt theme unequal to the last
|
|
// (test/perf/design_bench_test.dart).
|
|
final Map<Color, Decoration> _tabIndicators = {};
|
|
final Map<(Color, Color), WidgetStateProperty<Color?>> _trackOutlines = {};
|
|
|
|
/// [base] with Paper's controls: buttons, menus, chips, fields, search bars,
|
|
/// tabs, segmented buttons, switches, checkboxes, sliders, badges and
|
|
/// progress, all in [paperRadius] corners with hairline outlines, no
|
|
/// elevation and the ink-blue accent.
|
|
ThemeData paperControls(ThemeData base, PaperSurfaces surfaces) {
|
|
final scheme = base.colorScheme;
|
|
const rounded = PaperSurfaces.rounded;
|
|
ButtonStyle buttons(ButtonStyle? style) =>
|
|
(style ?? const ButtonStyle()).copyWith(
|
|
shape: const WidgetStatePropertyAll(rounded),
|
|
elevation: const WidgetStatePropertyAll(0),
|
|
shadowColor: const WidgetStatePropertyAll(_clear),
|
|
);
|
|
final outline = WidgetStatePropertyAll(BorderSide(color: scheme.outline));
|
|
final menu = MenuStyle(
|
|
backgroundColor: WidgetStatePropertyAll(surfaces.floating),
|
|
elevation: const WidgetStatePropertyAll(PaperSurfaces.floatElevation),
|
|
shadowColor: WidgetStatePropertyAll(surfaces.shadow),
|
|
surfaceTintColor: const WidgetStatePropertyAll(_clear),
|
|
shape: WidgetStatePropertyAll(surfaces.framed),
|
|
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 4)),
|
|
);
|
|
return base.copyWith(
|
|
menuTheme: MenuThemeData(style: menu),
|
|
dropdownMenuTheme: DropdownMenuThemeData(menuStyle: menu),
|
|
menuButtonTheme: MenuButtonThemeData(
|
|
style: MenuItemButton.styleFrom(shape: rounded),
|
|
),
|
|
filledButtonTheme: FilledButtonThemeData(
|
|
style: buttons(base.filledButtonTheme.style),
|
|
),
|
|
elevatedButtonTheme: ElevatedButtonThemeData(
|
|
style: buttons(base.elevatedButtonTheme.style).copyWith(
|
|
backgroundColor: WidgetStatePropertyAll(scheme.surface),
|
|
side: outline,
|
|
),
|
|
),
|
|
outlinedButtonTheme: OutlinedButtonThemeData(
|
|
style: buttons(base.outlinedButtonTheme.style).copyWith(side: outline),
|
|
),
|
|
textButtonTheme: TextButtonThemeData(
|
|
style: buttons(base.textButtonTheme.style),
|
|
),
|
|
iconButtonTheme: IconButtonThemeData(
|
|
style: buttons(base.iconButtonTheme.style),
|
|
),
|
|
segmentedButtonTheme: SegmentedButtonThemeData(
|
|
style: buttons(base.segmentedButtonTheme.style).copyWith(
|
|
side: WidgetStatePropertyAll(BorderSide(color: scheme.outline)),
|
|
),
|
|
),
|
|
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
|
elevation: 0,
|
|
focusElevation: 0,
|
|
hoverElevation: 0,
|
|
highlightElevation: 0,
|
|
backgroundColor: scheme.surface,
|
|
foregroundColor: scheme.primary,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: PaperSurfaces.corners,
|
|
side: BorderSide(color: scheme.outline),
|
|
),
|
|
),
|
|
chipTheme: ChipThemeData(
|
|
backgroundColor: _clear,
|
|
selectedColor: scheme.secondaryContainer,
|
|
shape: surfaces.framed,
|
|
side: surfaces.hairline,
|
|
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 rule it draws itself) keeps none in every state.
|
|
// An underline is a writing line on the page, not a box.
|
|
inputDecorationTheme: InputDecorationTheme(
|
|
border: UnderlineInputBorder(
|
|
borderSide: BorderSide(color: scheme.outline),
|
|
),
|
|
),
|
|
searchBarTheme: SearchBarThemeData(
|
|
elevation: const WidgetStatePropertyAll(0),
|
|
shape: const WidgetStatePropertyAll(rounded),
|
|
side: WidgetStatePropertyAll(surfaces.hairline),
|
|
backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerLowest),
|
|
surfaceTintColor: const WidgetStatePropertyAll(_clear),
|
|
padding: const WidgetStatePropertyAll(
|
|
EdgeInsets.symmetric(horizontal: 12),
|
|
),
|
|
),
|
|
listTileTheme: const ListTileThemeData(shape: rounded),
|
|
expansionTileTheme: const ExpansionTileThemeData(
|
|
shape: Border(),
|
|
collapsedShape: Border(),
|
|
),
|
|
tabBarTheme: TabBarThemeData(
|
|
dividerColor: scheme.outlineVariant,
|
|
labelColor: scheme.onSurface,
|
|
unselectedLabelColor: scheme.onSurfaceVariant,
|
|
indicatorSize: TabBarIndicatorSize.label,
|
|
indicator: _tabIndicators[scheme.primary] ??= UnderlineTabIndicator(
|
|
borderSide: BorderSide(color: scheme.primary, width: 2),
|
|
),
|
|
),
|
|
switchTheme: SwitchThemeData(
|
|
trackOutlineColor: _trackOutlines[(scheme.primary, scheme.outline)] ??=
|
|
WidgetStateProperty.resolveWith(
|
|
(states) => states.contains(WidgetState.selected)
|
|
? scheme.primary
|
|
: scheme.outline,
|
|
),
|
|
trackOutlineWidth: const WidgetStatePropertyAll(1),
|
|
),
|
|
checkboxTheme: CheckboxThemeData(
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(3)),
|
|
),
|
|
side: WidgetStateBorderSide.resolveWith(
|
|
(states) => states.contains(WidgetState.selected)
|
|
? BorderSide(color: scheme.primary, width: 1.5)
|
|
: BorderSide(color: scheme.outline, width: 1.5),
|
|
),
|
|
),
|
|
// A thin rule with a small round thumb, like a reading-app slider.
|
|
sliderTheme: SliderThemeData(
|
|
trackHeight: 2,
|
|
activeTrackColor: scheme.primary,
|
|
inactiveTrackColor: scheme.outlineVariant,
|
|
thumbColor: scheme.primary,
|
|
overlayColor: scheme.primary.withValues(alpha: 0.1),
|
|
thumbShape: const RoundSliderThumbShape(
|
|
enabledThumbRadius: 7,
|
|
elevation: 0,
|
|
pressedElevation: 0,
|
|
),
|
|
overlayShape: const RoundSliderOverlayShape(overlayRadius: 16),
|
|
trackShape: const RoundedRectSliderTrackShape(),
|
|
tickMarkShape: const RoundSliderTickMarkShape(tickMarkRadius: 1.5),
|
|
activeTickMarkColor: scheme.onPrimary,
|
|
inactiveTickMarkColor: scheme.outline,
|
|
valueIndicatorColor: scheme.inverseSurface,
|
|
valueIndicatorTextStyle: TextStyle(color: scheme.onInverseSurface),
|
|
),
|
|
// Counts in the accent's ink rather than an alarm red.
|
|
badgeTheme: BadgeThemeData(
|
|
backgroundColor: scheme.primary,
|
|
textColor: scheme.onPrimary,
|
|
padding: const EdgeInsets.symmetric(horizontal: 4),
|
|
),
|
|
progressIndicatorTheme: ProgressIndicatorThemeData(
|
|
color: scheme.primary,
|
|
linearTrackColor: scheme.outlineVariant,
|
|
circularTrackColor: _clear,
|
|
linearMinHeight: 2,
|
|
),
|
|
scrollbarTheme: const ScrollbarThemeData(
|
|
radius: Radius.circular(4),
|
|
thickness: WidgetStatePropertyAll(6),
|
|
),
|
|
);
|
|
}
|