Merge main (Compact design) into Glass
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user