8ca3d3e467
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
212 lines
7.2 KiB
Dart
212 lines
7.2 KiB
Dart
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter/material.dart';
|
||
|
||
import 'app_design.dart';
|
||
import 'app_design_tokens.dart';
|
||
import 'app_theme.dart';
|
||
import 'glass_controls.dart';
|
||
import 'glass_palette.dart';
|
||
|
||
/// Glass's corner radii, outer to inner: a floating sheet or dialog, then a
|
||
/// menu or card, then a field or a small card inside them, then a tooltip.
|
||
abstract final class GlassRadii {
|
||
static const double sheet = 20;
|
||
static const double card = 16;
|
||
static const double field = 14;
|
||
static const double small = 10;
|
||
}
|
||
|
||
/// The reading type: the interface sans a little roomier than Material's
|
||
/// body line, so long answers breathe on the glass.
|
||
const ReadingType glassReading = ReadingType(height: 1.55);
|
||
|
||
const Color _clear = Color(0x00000000);
|
||
|
||
/// Glass's surfaces for one brightness: the [GlassStyle] tints and the
|
||
/// glass edges every themed component shares.
|
||
class GlassSurfaces {
|
||
const GlassSurfaces(this.scheme, this.style);
|
||
|
||
final ColorScheme scheme;
|
||
final GlassStyle style;
|
||
|
||
bool get dark => scheme.brightness == Brightness.dark;
|
||
|
||
/// A floating piece's fill (menus, dialogs, sheets): nearly opaque, as
|
||
/// nothing behind it is blurred, so its text keeps its contrast over any
|
||
/// content.
|
||
Color get floating => style.solid.withValues(alpha: dark ? 0.96 : 0.94);
|
||
|
||
/// A glass edge in [radius] corners.
|
||
GlassBorder edge(double radius) => GlassBorder(
|
||
borderRadius: BorderRadius.all(Radius.circular(radius)),
|
||
highlight: style.highlight,
|
||
edge: style.edge,
|
||
);
|
||
|
||
/// The top-edge-only variant for a sheet rising from the bottom.
|
||
GlassBorder get sheetEdge => GlassBorder(
|
||
borderRadius: const BorderRadius.vertical(
|
||
top: Radius.circular(GlassRadii.sheet),
|
||
),
|
||
highlight: style.highlight,
|
||
edge: style.edge,
|
||
);
|
||
}
|
||
|
||
/// The Glass design's theme: a soft mesh gradient behind the app
|
||
/// ([GlassBackdrop]), clear scaffolds, translucent container roles,
|
||
/// frosted bars, rounded floating pieces (14–20px) with a light top edge
|
||
/// and gentle layered shadows, the interface sans with a little more
|
||
/// weight in titles, and one violet accent. Bubbles, code blocks and cards
|
||
/// are tints over the backdrop: only bars, the composer and floating pieces
|
||
/// blur ([GlassPill]).
|
||
ThemeData glassTheme(Brightness brightness, {String? fontFamily}) {
|
||
final dark = brightness == Brightness.dark;
|
||
final scheme = glassColorScheme(brightness);
|
||
final style = dark ? glassDarkStyle : glassLightStyle;
|
||
final surfaces = GlassSurfaces(scheme, style);
|
||
final base = ThemeData(
|
||
platform: kIsWeb ? TargetPlatform.android : null,
|
||
colorScheme: scheme,
|
||
fontFamily: fontFamily,
|
||
// Clear: the backdrop behind the app shows through every page.
|
||
scaffoldBackgroundColor: _clear,
|
||
canvasColor: surfaces.floating,
|
||
pageTransitionsTheme: appPageTransitions,
|
||
dividerColor: scheme.outlineVariant,
|
||
shadowColor: style.shadow,
|
||
extensions: [
|
||
AppDesignTokens(
|
||
design: AppDesign.glass,
|
||
ansi: dark ? glassDarkAccents : glassLightAccents,
|
||
selectedRow: SelectedRowStyle.glow,
|
||
reading: glassReading,
|
||
glass: style,
|
||
),
|
||
],
|
||
);
|
||
final text = glassTextTheme(base.textTheme);
|
||
return glassControls(
|
||
base.copyWith(
|
||
textTheme: text,
|
||
primaryTextTheme: glassTextTheme(base.primaryTextTheme),
|
||
appBarTheme: AppBarTheme(
|
||
backgroundColor: _clear,
|
||
foregroundColor: scheme.onSurface,
|
||
surfaceTintColor: _clear,
|
||
elevation: 0,
|
||
scrolledUnderElevation: 0,
|
||
),
|
||
// Only the glass edge and corners: each card variant keeps its own
|
||
// fill, so a selected graph node still reads apart.
|
||
cardTheme: CardThemeData(
|
||
elevation: 0,
|
||
shadowColor: _clear,
|
||
surfaceTintColor: _clear,
|
||
shape: surfaces.edge(GlassRadii.card),
|
||
),
|
||
dialogTheme: DialogThemeData(
|
||
backgroundColor: surfaces.floating,
|
||
surfaceTintColor: _clear,
|
||
elevation: 8,
|
||
shadowColor: style.shadow,
|
||
shape: surfaces.edge(GlassRadii.sheet),
|
||
),
|
||
bottomSheetTheme: BottomSheetThemeData(
|
||
backgroundColor: surfaces.floating,
|
||
modalBackgroundColor: surfaces.floating,
|
||
surfaceTintColor: _clear,
|
||
elevation: 8,
|
||
modalElevation: 8,
|
||
shadowColor: style.shadow,
|
||
shape: surfaces.sheetEdge,
|
||
dragHandleColor: scheme.outline,
|
||
),
|
||
popupMenuTheme: PopupMenuThemeData(
|
||
color: surfaces.floating,
|
||
surfaceTintColor: _clear,
|
||
elevation: 6,
|
||
shadowColor: style.shadow,
|
||
shape: surfaces.edge(GlassRadii.card),
|
||
),
|
||
snackBarTheme: SnackBarThemeData(
|
||
backgroundColor: scheme.inverseSurface.withValues(alpha: 0.94),
|
||
contentTextStyle: base.textTheme.bodyMedium?.copyWith(
|
||
color: scheme.onInverseSurface,
|
||
),
|
||
actionTextColor: scheme.inversePrimary,
|
||
elevation: 6,
|
||
behavior: SnackBarBehavior.floating,
|
||
shape: GlassBorder(
|
||
borderRadius: const BorderRadius.all(
|
||
Radius.circular(GlassRadii.field),
|
||
),
|
||
highlight: dark ? const Color(0x99FFFFFF) : const Color(0x4DFFFFFF),
|
||
edge: _clear,
|
||
),
|
||
),
|
||
tooltipTheme: TooltipThemeData(
|
||
decoration: ShapeDecoration(
|
||
color: scheme.inverseSurface.withValues(alpha: 0.92),
|
||
shape: GlassBorder(
|
||
borderRadius: const BorderRadius.all(
|
||
Radius.circular(GlassRadii.small),
|
||
),
|
||
highlight: dark ? const Color(0x80FFFFFF) : const Color(0x40FFFFFF),
|
||
edge: _clear,
|
||
),
|
||
),
|
||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||
textStyle: base.textTheme.bodySmall?.copyWith(
|
||
color: scheme.onInverseSurface,
|
||
),
|
||
),
|
||
dividerTheme: DividerThemeData(
|
||
color: scheme.outlineVariant,
|
||
thickness: 1,
|
||
space: 1,
|
||
),
|
||
navigationRailTheme: NavigationRailThemeData(
|
||
backgroundColor: _clear,
|
||
elevation: 0,
|
||
indicatorColor: scheme.secondaryContainer,
|
||
),
|
||
navigationBarTheme: NavigationBarThemeData(
|
||
backgroundColor: style.bar,
|
||
elevation: 0,
|
||
indicatorColor: scheme.secondaryContainer,
|
||
surfaceTintColor: _clear,
|
||
),
|
||
drawerTheme: DrawerThemeData(
|
||
backgroundColor: surfaces.floating,
|
||
surfaceTintColor: _clear,
|
||
elevation: 8,
|
||
shadowColor: style.shadow,
|
||
),
|
||
textSelectionTheme: TextSelectionThemeData(
|
||
cursorColor: scheme.primary,
|
||
selectionColor: scheme.primary.withValues(alpha: dark ? 0.35 : 0.22),
|
||
selectionHandleColor: scheme.primary,
|
||
),
|
||
),
|
||
surfaces,
|
||
);
|
||
}
|
||
|
||
/// [base] for Glass: the interface sans throughout, titles and labels a
|
||
/// step heavier (semibold) so they hold on a light, busy ground.
|
||
TextTheme glassTextTheme(TextTheme base) {
|
||
TextStyle? semibold(TextStyle? style) =>
|
||
style?.copyWith(fontWeight: FontWeight.w600);
|
||
return base.copyWith(
|
||
headlineLarge: semibold(base.headlineLarge),
|
||
headlineMedium: semibold(base.headlineMedium),
|
||
headlineSmall: semibold(base.headlineSmall),
|
||
titleLarge: semibold(base.titleLarge),
|
||
titleMedium: semibold(base.titleMedium),
|
||
titleSmall: semibold(base.titleSmall),
|
||
labelLarge: semibold(base.labelLarge),
|
||
);
|
||
}
|