Merge main (Compact design) into Glass

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 23:22:56 +00:00
93 changed files with 4110 additions and 313 deletions
+3 -1
View File
@@ -423,7 +423,9 @@ class _SegmentedBarState extends State<SegmentedBar> {
titleShare ??
(widget.separateActionIslands ? .10 : SegmentedBar.minTitleShare);
final besideTitle =
width - (leading == null ? 0 : segmentedPieceHeight() + 8) - 8;
width -
(leading == null ? 0 : segmentedPieceHeight(context) + 8) -
8;
// Actions that cannot move (a model picker) may take the room down
// to the title's minimum share; the rest leave for the More menu
// before the title goes under its own width.
+16 -6
View File
@@ -1,11 +1,17 @@
import 'package:flutter/material.dart';
import '../theme/app_design_tokens.dart';
import 'glass_pill.dart';
import 'segmented_bar_motion.dart';
/// The smallest height of every piece of a [SegmentedBar]: the platform's
/// minimum touch target, so a round Back is a circle.
double segmentedPieceHeight() => kMinInteractiveDimension;
/// minimum touch target, so a round Back is a circle. Under a dense design
/// at [context] the pieces are 40px: its 32px controls with a 4px edge, still
/// a comfortable touch target.
double segmentedPieceHeight([BuildContext? context]) =>
context != null && AppDesignTokens.of(context).density.dense
? 40
: kMinInteractiveDimension;
/// One rounded piece of a segmented bar: a [GlassPill] at least the
/// platform's touch-target size.
@@ -19,7 +25,7 @@ class SegmentedPill extends StatelessWidget {
@override
Widget build(BuildContext context) {
final height = segmentedPieceHeight();
final height = segmentedPieceHeight(context);
// A stadium whose content is as wide as it is tall is a circle.
return GlassPill(
fill: fill,
@@ -75,6 +81,10 @@ Widget? impliedSegmentedLeading(BuildContext context) {
/// The title pill's horizontal padding on each side.
const double segmentedTitlePadding = 16;
/// [segmentedTitlePadding] under the design at [context] (12px when dense).
double segmentedTitlePaddingOf(BuildContext context) =>
AppDesignTokens.of(context).density.inset(segmentedTitlePadding);
/// The width the title pill needs to show [title] and [subtitle] whole (at
/// the text scale at [context]).
double segmentedTitleWidth(
@@ -113,7 +123,7 @@ double segmentedTitleWidth(
measure(' ', subtitleStyle));
final text = measure(title, titleStyle);
return (text > subWidth ? text : subWidth).ceilToDouble() +
segmentedTitlePadding * 2;
segmentedTitlePaddingOf(context) * 2;
}
/// The title, with an optional one-line subtitle, in one pill; pressing it
@@ -156,8 +166,8 @@ class SegmentedTitlePill extends StatelessWidget {
);
final subtitle = this.subtitle ?? '';
final content = Padding(
padding: const EdgeInsets.symmetric(
horizontal: segmentedTitlePadding,
padding: EdgeInsets.symmetric(
horizontal: segmentedTitlePaddingOf(context),
vertical: 4,
),
child: Row(
+5 -2
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import '../theme/app_design_tokens.dart';
/// The app's one search field.
///
@@ -53,8 +54,10 @@ class AppSearchField extends StatelessWidget {
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
const radius = BorderRadius.all(Radius.circular(28));
const stadium = OutlineInputBorder(
final radius = AppDesignTokens.of(
context,
).denseCorners(const BorderRadius.all(Radius.circular(28)));
final stadium = OutlineInputBorder(
borderRadius: radius,
borderSide: BorderSide.none,
);
+13 -5
View File
@@ -5,6 +5,11 @@ import '../theme/app_design_tokens.dart';
/// avatar ([CircleAvatar]'s default).
const double kAppListAvatarSize = 40;
/// The leading avatar's size under the design at [context]:
/// [kAppListAvatarSize], or a dense design's smaller one.
double appListAvatarSize(BuildContext context) =>
AppDesignTokens.of(context).density.avatarSize;
/// A list row's leading identity: an icon or an initial on a tinted circle,
/// with an optional corner badge (a chat's activity indicator).
///
@@ -52,16 +57,19 @@ class AppListAvatar extends StatelessWidget {
(foreground == null
? Theme.of(context).colorScheme.surfaceContainerHighest
: mark.withValues(alpha: 0.14));
// The mark keeps the same proportion of the circle at every density.
final tokens = AppDesignTokens.of(context);
final size = tokens.density.avatarSize;
final scale = size / kAppListAvatarSize;
final initialStyle =
(Theme.of(context).textTheme.titleMedium ?? const TextStyle()).copyWith(
color: mark,
fontSize: 18,
fontSize: 18 * scale,
fontWeight: FontWeight.w700,
height: 1,
);
// A flat design (Terminal) frames the mark in a square box instead of a
// tinted circle.
final tokens = AppDesignTokens.of(context);
final decoration = tokens.flat
? BoxDecoration(
border: Border.all(color: mark.withValues(alpha: 0.55)),
@@ -69,18 +77,18 @@ class AppListAvatar extends StatelessWidget {
)
: BoxDecoration(color: fill, shape: BoxShape.circle);
final circle = SizedBox.square(
dimension: kAppListAvatarSize,
dimension: size,
child: DecoratedBox(
decoration: decoration,
child: Center(
// The glyph is identity, not reading text: it scales down to stay
// inside the circle under large text instead of overflowing it.
child: Padding(
padding: const EdgeInsets.all(8),
padding: EdgeInsets.all(8 * scale),
child: FittedBox(
fit: BoxFit.scaleDown,
child: IconTheme.merge(
data: IconThemeData(color: mark, size: 22),
data: IconThemeData(color: mark, size: 22 * scale),
child: DefaultTextStyle(style: initialStyle, child: child),
),
),
+71 -12
View File
@@ -157,6 +157,7 @@ class AppListRow extends StatelessWidget {
selected: selected,
emphasized: emphasized,
);
final metrics = _RowMetrics.of(context);
return Semantics(
container: true,
selected: selected,
@@ -167,14 +168,16 @@ class AppListRow extends StatelessWidget {
final minimal = constraints.maxWidth < kAppListRowMinimalWidth;
final showLeading = leading != null && !minimal;
final showMenu = menu != null && !minimal;
final start = compact ? 12.0 : kAppListRowInset;
final avatarGap = compact ? _compactAvatarGap : _avatarGap;
final start = compact ? metrics.compactInset : metrics.inset;
final avatarGap = compact
? metrics.compactAvatarGap
: metrics.avatarGap;
final content = Padding(
padding: EdgeInsetsDirectional.only(
start: start,
end: showMenu ? 4 : kAppListRowInset,
top: kAppListRowVerticalPadding,
bottom: kAppListRowVerticalPadding,
end: showMenu ? 4 : metrics.inset,
top: metrics.vertical,
bottom: metrics.vertical,
),
child: Row(
children: [
@@ -188,7 +191,7 @@ class AppListRow extends StatelessWidget {
padding: EdgeInsetsDirectional.only(end: avatarGap),
child: leading,
),
Expanded(child: _text(styles, compact)),
Expanded(child: _text(styles, metrics, compact)),
if (showMenu)
Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
@@ -248,7 +251,12 @@ class AppListRow extends StatelessWidget {
key: tapKey,
onTap: onTap,
onLongPress: onLongPress,
child: content,
child: metrics.minHeight > 0
? ConstrainedBox(
constraints: BoxConstraints(minHeight: metrics.minHeight),
child: Center(widthFactor: 1, child: content),
)
: content,
),
);
// The colour bar runs the row's whole height, divider included, and
@@ -282,7 +290,7 @@ class AppListRow extends StatelessWidget {
// not known here, so a selectable row's divider starts at the inset.
final textStart = selectionControl != null
? start
: start + (showLeading ? kAppListAvatarSize + avatarGap : 0);
: start + (showLeading ? metrics.avatar + avatarGap : 0);
final line = Padding(
padding: EdgeInsetsDirectional.only(start: textStart),
child: SizedBox(
@@ -327,7 +335,7 @@ class AppListRow extends StatelessWidget {
);
}
Widget _text(_RowStyles styles, bool compact) {
Widget _text(_RowStyles styles, _RowMetrics metrics, bool compact) {
final line = compact ? (compactSubtitle ?? subtitle) : subtitle;
final time = _time(styles);
final titleLine = LayoutBuilder(
@@ -360,7 +368,7 @@ class AppListRow extends StatelessWidget {
final detailLine = detail == null || (compact && !compactDetail)
? null
: Padding(
padding: const EdgeInsets.only(top: _lineGap),
padding: EdgeInsets.only(top: metrics.lineGap),
child: DefaultTextStyle(
style: styles.subtitle,
maxLines: 1,
@@ -375,7 +383,7 @@ class AppListRow extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
titleLine,
const SizedBox(height: _lineGap),
SizedBox(height: metrics.lineGap),
timeLine,
],
);
@@ -385,7 +393,7 @@ class AppListRow extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
titleLine,
const SizedBox(height: _lineGap),
SizedBox(height: metrics.lineGap),
Row(
children: [
if (subtitleLeading != null)
@@ -415,6 +423,57 @@ class AppListRow extends StatelessWidget {
}
}
/// The row's spacing under the design's density: the comfortable constants,
/// or a dense design's tighter ones (a 36px single-line row and a ~52px
/// two-line row on a pointer device; at least 40px on touch).
class _RowMetrics {
const _RowMetrics({
required this.inset,
required this.compactInset,
required this.avatarGap,
required this.compactAvatarGap,
required this.vertical,
required this.lineGap,
required this.avatar,
required this.minHeight,
});
factory _RowMetrics.of(BuildContext context) {
final density = AppDesignTokens.of(context).density;
if (!density.dense) return _comfortable;
return _RowMetrics(
inset: density.inset(kAppListRowInset),
compactInset: density.inset(12),
avatarGap: density.space(_avatarGap),
compactAvatarGap: density.space(_compactAvatarGap),
vertical: density.space(kAppListRowVerticalPadding),
lineGap: 0,
avatar: density.avatarSize,
minHeight: density.minTouchRow,
);
}
static const _comfortable = _RowMetrics(
inset: kAppListRowInset,
compactInset: 12,
avatarGap: _avatarGap,
compactAvatarGap: _compactAvatarGap,
vertical: kAppListRowVerticalPadding,
lineGap: _lineGap,
avatar: kAppListAvatarSize,
minHeight: 0,
);
final double inset;
final double compactInset;
final double avatarGap;
final double compactAvatarGap;
final double vertical;
final double lineGap;
final double avatar;
final double minHeight;
}
/// The row's text styles, from the host's own type scale.
class _RowStyles {
const _RowStyles(this.title, this.subtitle, this.time, this.divider);
+21 -1
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'app_design_tokens.dart';
import 'app_theme.dart';
import 'compact_theme.dart';
import 'glass_theme.dart';
import 'paper_theme.dart';
import 'terminal_theme.dart';
@@ -52,6 +53,14 @@ enum AppDesign {
'Warm paper, serif reading text and ink colours; calm for long reads.',
),
/// The Classic look packed tight for a big monitor: smaller type, thin
/// rows, 18px icons, an icon-only rail and modest corners.
compact(
'compact',
'Compact',
'Classic’s Material look, dense: small type, thin rows, more on screen.',
),
/// Translucent frosted panes over a soft gradient: rounded cards, light
/// glass edges and gentle depth.
glass(
@@ -109,9 +118,16 @@ enum AppDesign {
(standard, Brightness.dark) => appDarkTheme(fontFamily: fontFamily),
(terminal, _) => terminalTheme(brightness),
(paper, _) => paperTheme(brightness, fontFamily: fontFamily),
(compact, _) => compactTheme(brightness, fontFamily: fontFamily),
(glass, _) => glassTheme(brightness, fontFamily: fontFamily),
};
/// Whether this design packs the interface densely
/// ([DesignDensity.dense]); its theme hosts switch to and from it without
/// a blend ([AppDesignController.themeAnimationDuration]).
bool get dense =>
light().extension<AppDesignTokens>()?.density.dense ?? false;
/// Whether the device's interface font applies under this design (Paper
/// keeps it for its interface text and sets reading text in its serif).
bool get usesInterfaceFont => this != terminal;
@@ -121,7 +137,7 @@ enum AppDesign {
DesignSwatch swatch(Brightness brightness) {
final dark = brightness == Brightness.dark;
return switch (this) {
standard =>
standard || compact =>
dark
? const DesignSwatch(
Color(0xFF141416),
@@ -171,6 +187,10 @@ enum AppDesign {
),
};
}
/// How many lines of ink the picker's preview draws: Compact's packs more
/// into the same page.
int get swatchLines => this == compact ? 4 : 2;
}
/// A design's three defining colours, for the picker's small preview.
+22 -3
View File
@@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' show kThemeAnimationDuration;
import 'package:shared_preferences/shared_preferences.dart';
import 'app_design.dart';
@@ -87,7 +88,24 @@ class AppDesignController extends ChangeNotifier {
void preview(AppDesign? design) {
final shown = this.design;
_preview = design;
if (this.design != shown) notifyListeners();
if (this.design != shown) _shown(shown);
}
/// How long the theme hosts blend into the current design (their
/// `themeAnimationDuration`): Material's blend between designs of the same
/// density, none for a switch into or out of a dense design. A dense
/// design's sizes (icons, controls) have no value in a comfortable theme to
/// blend from, so a blend would pass every icon through size zero, and in
/// the browser (skwasm) laying out the near-zero icon glyphs could hang.
Duration get themeAnimationDuration =>
_snapTheme ? Duration.zero : kThemeAnimationDuration;
bool _snapTheme = false;
/// The shown design changed from [before]: decide the hosts' blend and
/// tell them.
void _shown(AppDesign before) {
_snapTheme = before.dense || design.dense;
notifyListeners();
}
/// The last choice could not be stored on this device.
@@ -100,8 +118,9 @@ class AppDesignController extends ChangeNotifier {
if (revision != _revision || id == null) return;
final design = AppDesign.fromId(id);
if (design == _design) return;
final shown = this.design;
_design = design;
if (_preview == null) notifyListeners();
if (_preview == null) _shown(shown);
}
/// Applies [design] now and stores it.
@@ -111,7 +130,7 @@ class AppDesignController extends ChangeNotifier {
final shown = this.design;
_preview = null;
_design = design;
if (design != shown) notifyListeners();
if (design != shown) _shown(shown);
final saved = await _store.save(design.id);
if (revision != _revision || saved != _saveFailed) return;
_saveFailed = !saved;
+11 -2
View File
@@ -1,6 +1,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
export 'design_density.dart';
/// How the chat transcript draws a conversation. Each design picks one; the
/// transcript widgets branch on it, never on the design itself.
enum TranscriptStyle {
@@ -59,6 +61,7 @@ class ReadingType {
this.measure,
this.scale = 1,
this.figureWidth = 0.5,
this.paragraphGap = 0.9,
});
/// The reading face; null keeps the theme's body face.
@@ -78,6 +81,10 @@ class ReadingType {
/// [measure] is worth (half an em for Source Serif's figures).
final double figureWidth;
/// The gap between two paragraphs of an answer, in lines of reading text
/// (before text scaling): about a line by default, less for a dense design.
final double paragraphGap;
/// [base] in the reading face, size and line height.
TextStyle? apply(TextStyle? base) {
if (base == null) return null;
@@ -103,8 +110,10 @@ class ReadingType {
other.height == height &&
other.measure == measure &&
other.scale == scale &&
other.figureWidth == figureWidth;
other.figureWidth == figureWidth &&
other.paragraphGap == paragraphGap;
@override
int get hashCode => Object.hash(family, height, measure, scale, figureWidth);
int get hashCode =>
Object.hash(family, height, measure, scale, figureWidth, paragraphGap);
}
+16 -1
View File
@@ -69,6 +69,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
this.reading = const ReadingType(),
this.chatColorSaturation = 1,
this.glass,
this.density = DesignDensity.comfortable,
});
/// The Classic design: every widget keeps its own shapes.
@@ -120,6 +121,10 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
/// corners grow. Null for an opaque design (every surface keeps its fill).
final GlassStyle? glass;
/// How tightly the interface is packed: spacing, icon and avatar sizes,
/// the rail and the window title bar ([DesignDensity.compact] for Compact).
final DesignDensity density;
/// Whether the transcript draws prompt and tool lines rather than bubbles.
bool get terminal => transcript == TranscriptStyle.prompt;
@@ -154,6 +159,12 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
return glass?.corners(designed) ?? designed;
}
/// [designed] corners, or [radius] corners under a dense design: for the
/// surfaces whose own corners the comfortable designs keep (floating
/// windows, search thumbnails), so only a dense design rounds them alike.
BorderRadius denseCorners(BorderRadius designed) =>
density.dense ? corners(designed) : designed;
/// [designed] (a widget's own fill) or, under a flat design, its [panel].
Color panelFill(ColorScheme scheme, Color designed) =>
flat ? panel ?? scheme.surfaceContainerLow : designed;
@@ -188,6 +199,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
ReadingType? reading,
double? chatColorSaturation,
GlassStyle? glass,
DesignDensity? density,
}) => AppDesignTokens(
design: design ?? this.design,
radius: radius ?? this.radius,
@@ -202,6 +214,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
reading: reading ?? this.reading,
chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation,
glass: glass ?? this.glass,
density: density ?? this.density,
);
// Value equality keeps a rebuilt theme equal to the one it replaces, so
@@ -222,7 +235,8 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
other.selectedRow == selectedRow &&
other.reading == reading &&
other.chatColorSaturation == chatColorSaturation &&
other.glass == glass;
other.glass == glass &&
other.density == density;
@override
int get hashCode => Object.hash(
@@ -239,6 +253,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
reading,
chatColorSaturation,
glass,
density,
);
/// Designs switch whole: a theme animation snaps halfway rather than
+197
View File
@@ -0,0 +1,197 @@
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. Their text
/// keeps each component's own Material role (already at Compact's sizes):
/// a component theme that sets a text-theme style cannot be lerped against
/// Default's unset one, which breaks a live design switch. 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;
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),
),
// 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,
),
menuTheme: MenuThemeData(style: menu),
dropdownMenuTheme: DropdownMenuThemeData(
menuStyle: menu,
inputDecorationTheme: const InputDecorationTheme(isDense: true),
),
menuButtonTheme: MenuButtonThemeData(
style: MenuItemButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 12),
minimumSize: const Size(0, 32),
iconSize: icon,
),
),
popupMenuTheme: PopupMenuThemeData(
shape: _rounded,
menuPadding: const EdgeInsets.symmetric(vertical: 4),
),
dialogTheme: DialogThemeData(
shape: _rounded,
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,
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),
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),
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),
),
),
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,
iconTheme: const WidgetStatePropertyAll(IconThemeData(size: icon)),
),
tabBarTheme: TabBarThemeData(
labelPadding: const EdgeInsets.symmetric(horizontal: 12),
),
dividerTheme: const DividerThemeData(space: 8, thickness: 1),
badgeTheme: BadgeThemeData(
smallSize: 6,
largeSize: 14,
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),
);
}
+47
View File
@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'app_design.dart';
import 'app_design_tokens.dart';
import 'app_theme.dart';
import 'compact_controls.dart';
import 'compact_typography.dart';
/// Compact's corner radius: every card, field, button, chip, menu, dialog,
/// sheet, tooltip, snack bar, bubble and window takes it.
const double compactRadius = 6;
/// The Compact design's theme: Default's Material 3 colours and surfaces,
/// packed for a big monitor and long runs and chats. A smaller type scale
/// ([compactTextTheme]), Material's compact visual density, 18px icons, and
/// [compactRadius] corners on every surface. On a touch device controls keep
/// a 40px tap target (Material's padded target under compact density); on a
/// pointer device they shrink to their drawn size.
ThemeData compactTheme(Brightness brightness, {String? fontFamily}) {
final standard = brightness == Brightness.dark
? appDarkTheme(fontFamily: fontFamily)
: appLightTheme(fontFamily: fontFamily);
final textTheme = compactTextTheme(standard.textTheme);
final themed = standard.copyWith(
visualDensity: VisualDensity.compact,
materialTapTargetSize: DesignDensity.pointerPlatform
? MaterialTapTargetSize.shrinkWrap
: MaterialTapTargetSize.padded,
textTheme: textTheme,
primaryTextTheme: compactTextTheme(standard.primaryTextTheme),
iconTheme: standard.iconTheme.copyWith(
size: DesignDensity.compact.iconSize,
),
primaryIconTheme: standard.primaryIconTheme.copyWith(
size: DesignDensity.compact.iconSize,
),
extensions: const [
AppDesignTokens(
design: AppDesign.compact,
radius: compactRadius,
reading: compactReading,
density: DesignDensity.compact,
),
],
);
return compactControls(themed);
}
+36
View File
@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'app_design_styles.dart';
/// Compact's reading type: the interface face at the dense body size
/// (`bodyLarge`, 14px), a little more line height than the role's so long
/// answers stay easy to follow, and about two thirds of a line between
/// paragraphs.
const ReadingType compactReading = ReadingType(height: 1.5, paragraphGap: 0.6);
/// [base] (Material 3's type scale, in the device's interface face) at
/// Compact's sizes: body 13px, labels 11-12px, list and dialog titles 14 and
/// 18px. Line heights sit on a 2px step so rows of mixed roles still line up
/// on the 4px grid. Weights, colours, families and tracking stay Material's;
/// text scaling still applies on top.
TextTheme compactTextTheme(TextTheme base) {
TextStyle? sized(TextStyle? style, double size, double line) =>
style?.copyWith(fontSize: size, height: line / size);
return base.copyWith(
displayLarge: sized(base.displayLarge, 44, 52),
displayMedium: sized(base.displayMedium, 36, 44),
displaySmall: sized(base.displaySmall, 28, 36),
headlineLarge: sized(base.headlineLarge, 26, 32),
headlineMedium: sized(base.headlineMedium, 22, 28),
headlineSmall: sized(base.headlineSmall, 20, 26),
titleLarge: sized(base.titleLarge, 18, 24),
titleMedium: sized(base.titleMedium, 14, 20),
titleSmall: sized(base.titleSmall, 13, 18),
bodyLarge: sized(base.bodyLarge, 14, 20),
bodyMedium: sized(base.bodyMedium, 13, 18),
bodySmall: sized(base.bodySmall, 11.5, 16),
labelLarge: sized(base.labelLarge, 13, 18),
labelMedium: sized(base.labelMedium, 12, 16),
labelSmall: sized(base.labelSmall, 11, 14),
);
}
+119
View File
@@ -0,0 +1,119 @@
import 'package:flutter/foundation.dart';
/// How tightly a design packs the interface: the spacing inside and between
/// components, icon and avatar sizes, the navigation rail's width and labels
/// and the floating window title bar. [comfortable] is the Default look;
/// every widget that reads a density keeps its own value under it, so the
/// comfortable designs draw exactly as before.
///
/// A dense design sets [spacing] below 1: [space] then scales a widget's own
/// spacing and snaps it to the 4px grid, so every component tightens by the
/// same proportion instead of each picking its own number.
@immutable
class DesignDensity {
const DesignDensity({
this.spacing = 1,
this.iconSize,
this.avatarSize = 40,
this.railWidth = 96,
this.railLabels = true,
this.titleBarHeight = 40,
});
/// The Default density.
static const DesignDensity comfortable = DesignDensity();
/// The Compact density: spacing at 60% on the 4px grid, 18px icons, 28px
/// avatars, an icon-only 64px rail and a 32px window title bar.
static const DesignDensity compact = DesignDensity(
spacing: 0.6,
iconSize: 18,
avatarSize: 28,
railWidth: 64,
railLabels: false,
titleBarHeight: 32,
);
/// The proportion of a widget's own spacing this density keeps.
final double spacing;
/// The interface's icon size; null keeps Material's 24.
final double? iconSize;
/// A list row's leading avatar.
final double avatarSize;
/// The destination rail's width on a wide window.
final double railWidth;
/// Whether the rail labels its destinations under their icons; without
/// them the rail shows icons with tooltips.
final bool railLabels;
/// A floating window's title bar height, before text scaling.
final double titleBarHeight;
/// Whether this density is tighter than [comfortable].
bool get dense => spacing < 1;
/// [comfortable] spacing under this density: unchanged at [spacing] 1,
/// otherwise scaled and snapped to the 4px grid (a gap under 4px keeps a
/// 2px step, so a hairline gap never collapses to nothing).
double space(double comfortable) {
if (spacing == 1 || comfortable <= 0) return comfortable;
final scaled = comfortable * spacing;
if (scaled < 4) return scaled < 3 ? 2 : 4;
return (scaled / 4).round() * 4.0;
}
/// [comfortable] edge inset (a row's or a panel's side padding) under this
/// density: halfway between [space] and the comfortable value, on the 4px
/// grid, so a dense row's text still keeps clear of the pane's edge
/// (16px becomes 12px at Compact).
double inset(double comfortable) {
if (spacing == 1 || comfortable <= 0) return comfortable;
final scaled = comfortable * (1 + spacing) / 2;
return scaled < 4 ? 4 : (scaled / 4).round() * 4.0;
}
/// The least height a tappable row keeps under this density: nothing
/// beyond its content when comfortable (its own padding already gives
/// room) or on a pointer device, and 40px on a touch device, so a dense
/// row stays easy to hit with a finger.
double get minTouchRow {
if (!dense) return 0;
return pointerPlatform ? 0 : 40;
}
/// Whether the device drives the app with a pointer (desktop, including a
/// desktop browser). Reads the device's platform, not the theme's: web
/// themes are pinned to Android.
static bool get pointerPlatform => switch (defaultTargetPlatform) {
TargetPlatform.macOS ||
TargetPlatform.linux ||
TargetPlatform.windows => true,
TargetPlatform.android ||
TargetPlatform.iOS ||
TargetPlatform.fuchsia => false,
};
@override
bool operator ==(Object other) =>
other is DesignDensity &&
other.spacing == spacing &&
other.iconSize == iconSize &&
other.avatarSize == avatarSize &&
other.railWidth == railWidth &&
other.railLabels == railLabels &&
other.titleBarHeight == titleBarHeight;
@override
int get hashCode => Object.hash(
spacing,
iconSize,
avatarSize,
railWidth,
railLabels,
titleBarHeight,
);
}