221 lines
8.1 KiB
Dart
221 lines
8.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'compact_theme.dart';
|
|
|
|
const BorderRadius _corners = BorderRadius.all(Radius.circular(compactRadius));
|
|
const RoundedRectangleBorder _rounded = RoundedRectangleBorder(
|
|
borderRadius: _corners,
|
|
);
|
|
|
|
/// [base] with Compact's controls: Default's Material components at dense
|
|
/// heights, in [compactRadius] corners, with 4px-grid paddings. Floating
|
|
/// surfaces (menus, dialogs, sheets, tooltips, snack bars) keep Material's
|
|
/// elevation and fills; only their corners and insets change.
|
|
ThemeData compactControls(ThemeData base) {
|
|
final scheme = base.colorScheme;
|
|
final text = base.textTheme;
|
|
const icon = 18.0;
|
|
// Buttons: 32px tall under compact density, 12px side padding, 18px icons.
|
|
ButtonStyle buttons() => const ButtonStyle(
|
|
shape: WidgetStatePropertyAll(_rounded),
|
|
padding: WidgetStatePropertyAll(EdgeInsets.symmetric(horizontal: 12)),
|
|
iconSize: WidgetStatePropertyAll(icon),
|
|
);
|
|
final menu = MenuStyle(
|
|
shape: const WidgetStatePropertyAll(_rounded),
|
|
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 4)),
|
|
visualDensity: VisualDensity.compact,
|
|
);
|
|
return base.copyWith(
|
|
filledButtonTheme: FilledButtonThemeData(style: buttons()),
|
|
elevatedButtonTheme: ElevatedButtonThemeData(style: buttons()),
|
|
outlinedButtonTheme: OutlinedButtonThemeData(style: buttons()),
|
|
textButtonTheme: TextButtonThemeData(
|
|
style: buttons().copyWith(
|
|
padding: const WidgetStatePropertyAll(
|
|
EdgeInsets.symmetric(horizontal: 8),
|
|
),
|
|
),
|
|
),
|
|
// Material 3's icon button ignores the theme's density unless its own
|
|
// style sets one: 32px drawn, its target padded to 40px on touch.
|
|
iconButtonTheme: const IconButtonThemeData(
|
|
style: ButtonStyle(
|
|
visualDensity: VisualDensity.compact,
|
|
iconSize: WidgetStatePropertyAll(icon),
|
|
// A square 32px button around its 18px icon.
|
|
padding: WidgetStatePropertyAll(EdgeInsets.all(7)),
|
|
shape: WidgetStatePropertyAll(_rounded),
|
|
),
|
|
),
|
|
segmentedButtonTheme: SegmentedButtonThemeData(
|
|
style: buttons().copyWith(
|
|
visualDensity: VisualDensity.compact,
|
|
textStyle: WidgetStatePropertyAll(text.labelLarge),
|
|
),
|
|
),
|
|
// A 40px action (Material's small FAB) and a 40px extended one.
|
|
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
|
shape: _rounded,
|
|
iconSize: icon,
|
|
sizeConstraints: const BoxConstraints.tightFor(width: 40, height: 40),
|
|
// Only a least height: a larger text scale still grows the label.
|
|
extendedSizeConstraints: const BoxConstraints(
|
|
minHeight: 40,
|
|
minWidth: 64,
|
|
),
|
|
extendedPadding: const EdgeInsetsDirectional.only(start: 12, end: 16),
|
|
extendedIconLabelSpacing: 8,
|
|
extendedTextStyle: text.labelLarge,
|
|
),
|
|
menuTheme: MenuThemeData(style: menu),
|
|
dropdownMenuTheme: DropdownMenuThemeData(
|
|
menuStyle: menu,
|
|
textStyle: text.bodyMedium,
|
|
inputDecorationTheme: const InputDecorationTheme(isDense: true),
|
|
),
|
|
menuButtonTheme: MenuButtonThemeData(
|
|
style: MenuItemButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
minimumSize: const Size(0, 32),
|
|
textStyle: text.bodyMedium,
|
|
iconSize: icon,
|
|
),
|
|
),
|
|
popupMenuTheme: PopupMenuThemeData(
|
|
shape: _rounded,
|
|
menuPadding: const EdgeInsets.symmetric(vertical: 4),
|
|
labelTextStyle: WidgetStatePropertyAll(text.bodyMedium),
|
|
textStyle: text.bodyMedium,
|
|
),
|
|
dialogTheme: DialogThemeData(
|
|
shape: _rounded,
|
|
titleTextStyle: text.titleLarge?.copyWith(color: scheme.onSurface),
|
|
contentTextStyle: text.bodyMedium?.copyWith(
|
|
color: scheme.onSurfaceVariant,
|
|
),
|
|
insetPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
|
actionsPadding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
|
),
|
|
bottomSheetTheme: const BottomSheetThemeData(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(
|
|
top: Radius.circular(compactRadius),
|
|
),
|
|
),
|
|
),
|
|
snackBarTheme: SnackBarThemeData(
|
|
shape: _rounded,
|
|
contentTextStyle: text.bodyMedium?.copyWith(
|
|
color: scheme.onInverseSurface,
|
|
),
|
|
insetPadding: const EdgeInsets.fromLTRB(12, 4, 12, 12),
|
|
),
|
|
tooltipTheme: TooltipThemeData(
|
|
decoration: BoxDecoration(
|
|
color: scheme.inverseSurface,
|
|
borderRadius: _corners,
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
textStyle: text.bodySmall?.copyWith(color: scheme.onInverseSurface),
|
|
waitDuration: const Duration(milliseconds: 400),
|
|
),
|
|
// A hairline on every card variant: the theme's shape replaces each
|
|
// variant's own, so an outlined card (a graph node) keeps its outline.
|
|
cardTheme: CardThemeData(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: _corners,
|
|
side: BorderSide(color: scheme.outlineVariant),
|
|
),
|
|
margin: const EdgeInsets.all(4),
|
|
),
|
|
chipTheme: ChipThemeData(
|
|
shape: _rounded,
|
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
|
labelPadding: const EdgeInsets.symmetric(horizontal: 4),
|
|
labelStyle: text.labelLarge,
|
|
iconTheme: const IconThemeData(size: 16),
|
|
),
|
|
inputDecorationTheme: const InputDecorationTheme(
|
|
isDense: true,
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
),
|
|
searchBarTheme: SearchBarThemeData(
|
|
shape: const WidgetStatePropertyAll(_rounded),
|
|
constraints: const BoxConstraints(minWidth: 240, minHeight: 36),
|
|
padding: const WidgetStatePropertyAll(
|
|
EdgeInsets.symmetric(horizontal: 12),
|
|
),
|
|
textStyle: WidgetStatePropertyAll(text.bodyMedium),
|
|
hintStyle: WidgetStatePropertyAll(
|
|
text.bodyMedium?.copyWith(color: scheme.onSurfaceVariant),
|
|
),
|
|
),
|
|
listTileTheme: const ListTileThemeData(
|
|
dense: true,
|
|
visualDensity: VisualDensity.compact,
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 12),
|
|
horizontalTitleGap: 12,
|
|
minLeadingWidth: 20,
|
|
minVerticalPadding: 6,
|
|
shape: _rounded,
|
|
),
|
|
expansionTileTheme: const ExpansionTileThemeData(
|
|
tilePadding: EdgeInsets.symmetric(horizontal: 12),
|
|
childrenPadding: EdgeInsets.symmetric(horizontal: 12),
|
|
shape: Border(),
|
|
collapsedShape: Border(),
|
|
),
|
|
navigationRailTheme: NavigationRailThemeData(
|
|
minWidth: 64,
|
|
labelType: NavigationRailLabelType.none,
|
|
indicatorShape: _rounded,
|
|
indicatorColor: scheme.secondaryContainer,
|
|
selectedIconTheme: IconThemeData(
|
|
size: icon,
|
|
color: scheme.onSecondaryContainer,
|
|
),
|
|
unselectedIconTheme: IconThemeData(
|
|
size: icon,
|
|
color: scheme.onSurfaceVariant,
|
|
),
|
|
groupAlignment: -1,
|
|
),
|
|
navigationBarTheme: NavigationBarThemeData(
|
|
height: 64,
|
|
indicatorShape: _rounded,
|
|
labelTextStyle: WidgetStatePropertyAll(text.labelMedium),
|
|
iconTheme: const WidgetStatePropertyAll(IconThemeData(size: icon)),
|
|
),
|
|
tabBarTheme: TabBarThemeData(
|
|
labelStyle: text.labelLarge,
|
|
unselectedLabelStyle: text.labelLarge,
|
|
labelPadding: const EdgeInsets.symmetric(horizontal: 12),
|
|
),
|
|
dividerTheme: const DividerThemeData(space: 8, thickness: 1),
|
|
badgeTheme: BadgeThemeData(
|
|
smallSize: 6,
|
|
largeSize: 14,
|
|
textStyle: text.labelSmall?.copyWith(fontSize: 10),
|
|
padding: const EdgeInsets.symmetric(horizontal: 4),
|
|
),
|
|
checkboxTheme: const CheckboxThemeData(
|
|
visualDensity: VisualDensity.compact,
|
|
),
|
|
radioTheme: const RadioThemeData(visualDensity: VisualDensity.compact),
|
|
scrollbarTheme: const ScrollbarThemeData(
|
|
radius: Radius.circular(3),
|
|
thickness: WidgetStatePropertyAll(6),
|
|
),
|
|
drawerTheme: const DrawerThemeData(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.horizontal(
|
|
right: Radius.circular(compactRadius),
|
|
),
|
|
),
|
|
),
|
|
datePickerTheme: const DatePickerThemeData(shape: _rounded),
|
|
timePickerTheme: const TimePickerThemeData(shape: _rounded),
|
|
);
|
|
}
|