Files
pipelines/app/lib/ui/theme/high_contrast_theme.dart
T

218 lines
7.5 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 'high_contrast_controls.dart';
import 'high_contrast_palette.dart';
import 'high_contrast_typography.dart';
/// High contrast's corner radius: moderate, so a box still reads as a box
/// at a glance in sunlight.
const double highContrastRadius = 6;
/// The width of every control's and panel's border.
const double highContrastStroke = 2;
/// The width of the keyboard focus ring.
const double highContrastFocusWidth = 3;
/// High contrast's shapes and borders, from its scheme.
class HighContrastSurfaces {
HighContrastSurfaces(this.scheme);
final ColorScheme scheme;
static const BorderRadius corners = BorderRadius.all(
Radius.circular(highContrastRadius),
);
/// The border of controls and floating pieces: 2px of the ink.
BorderSide get border =>
BorderSide(color: scheme.outline, width: highContrastStroke);
/// A structural rule (app bar, tab bar): 2px of the secondary ink, so the
/// page's structure stays quieter than its controls.
BorderSide get rule =>
BorderSide(color: scheme.outlineVariant, width: highContrastStroke);
RoundedRectangleBorder get framed =>
RoundedRectangleBorder(borderRadius: corners, side: border);
static const RoundedRectangleBorder rounded = RoundedRectangleBorder(
borderRadius: corners,
);
}
/// The High contrast design's theme: a pure black page with white ink and a
/// yellow accent (or pure white with black ink and a deep blue accent),
/// larger and heavier type, 2px borders on every control and panel, flat
/// surfaces without shadows, [highContrastRadius] corners, 48px targets on
/// every platform and a 3px keyboard focus ring ([FocusRingStyle]).
ThemeData highContrastTheme(Brightness brightness, {String? fontFamily}) {
final scheme = highContrastColorScheme(brightness);
final surfaces = HighContrastSurfaces(scheme);
final dark = brightness == Brightness.dark;
const clear = Color(0x00000000);
final base = ThemeData(
platform: kIsWeb ? TargetPlatform.android : null,
colorScheme: scheme,
fontFamily: fontFamily,
scaffoldBackgroundColor: scheme.surface,
canvasColor: scheme.surface,
pageTransitionsTheme: appPageTransitions,
// Touch-sized targets on a desktop too.
visualDensity: VisualDensity.standard,
materialTapTargetSize: MaterialTapTargetSize.padded,
dividerColor: scheme.outlineVariant,
disabledColor: highContrastDisabled(brightness),
hintColor: scheme.onSurfaceVariant,
shadowColor: clear,
hoverColor: scheme.onSurface.withValues(alpha: 0.12),
focusColor: scheme.primary.withValues(alpha: 0.24),
extensions: [
AppDesignTokens(
design: AppDesign.highContrast,
radius: highContrastRadius,
flat: true,
frame: scheme.outline,
panel: scheme.surface,
ansi: dark ? highContrastDarkAccents : highContrastLightAccents,
transcript: TranscriptStyle.boxed,
selectedRow: SelectedRowStyle.inverted,
stroke: highContrastStroke,
ringStroke: 3,
focusRing: FocusRingStyle(
color: scheme.primary,
halo: scheme.surface,
width: highContrastFocusWidth,
),
largeTargets: true,
minContrast: highContrastMinimum,
windowRadius: highContrastRadius,
snapSwitch: true,
),
],
);
final text = highContrastTextTheme(base.textTheme);
final framed = surfaces.framed;
return highContrastControls(
base.copyWith(
textTheme: text,
primaryTextTheme: highContrastTextTheme(base.primaryTextTheme),
appBarTheme: AppBarTheme(
backgroundColor: scheme.surface,
foregroundColor: scheme.onSurface,
surfaceTintColor: clear,
elevation: 0,
scrolledUnderElevation: 0,
shape: Border(bottom: surfaces.rule),
titleTextStyle: text.titleLarge?.copyWith(color: scheme.onSurface),
),
cardTheme: CardThemeData(
elevation: 0,
shadowColor: clear,
surfaceTintColor: clear,
shape: framed,
),
dialogTheme: DialogThemeData(
backgroundColor: scheme.surface,
surfaceTintColor: clear,
elevation: 0,
shape: framed,
),
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: scheme.surface,
modalBackgroundColor: scheme.surface,
surfaceTintColor: clear,
elevation: 0,
modalElevation: 0,
shape: RoundedRectangleBorder(
borderRadius: const BorderRadius.vertical(
top: Radius.circular(highContrastRadius),
),
side: surfaces.border,
),
dragHandleColor: scheme.onSurface,
),
popupMenuTheme: PopupMenuThemeData(
color: scheme.surface,
surfaceTintColor: clear,
elevation: 0,
shape: framed,
),
// The ink's own colour inverted, framed, so a snack bar stands apart
// from the page without a shadow.
snackBarTheme: SnackBarThemeData(
backgroundColor: scheme.inverseSurface,
contentTextStyle: text.bodyLarge?.copyWith(
color: scheme.onInverseSurface,
),
actionTextColor: scheme.inversePrimary,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: HighContrastSurfaces.corners,
side: BorderSide(
color: scheme.onInverseSurface,
width: highContrastStroke,
),
),
),
// Tooltips large and inverted, inside a border in the page colour so
// one over an inverted row still has an edge.
tooltipTheme: TooltipThemeData(
decoration: BoxDecoration(
color: scheme.inverseSurface,
borderRadius: HighContrastSurfaces.corners,
border: Border.all(color: scheme.surface, width: highContrastStroke),
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
textStyle: text.bodyMedium?.copyWith(
color: scheme.onInverseSurface,
fontWeight: FontWeight.w600,
),
),
dividerTheme: DividerThemeData(
color: scheme.outlineVariant,
thickness: 1,
space: 1,
),
navigationRailTheme: NavigationRailThemeData(
backgroundColor: scheme.surface,
elevation: 0,
indicatorColor: scheme.secondaryContainer,
indicatorShape: HighContrastSurfaces.rounded,
selectedIconTheme: IconThemeData(color: scheme.onSecondaryContainer),
unselectedIconTheme: IconThemeData(color: scheme.onSurface),
selectedLabelTextStyle: text.labelMedium?.copyWith(
color: scheme.onSurface,
fontWeight: FontWeight.w800,
),
unselectedLabelTextStyle: text.labelMedium?.copyWith(
color: scheme.onSurface,
),
),
navigationBarTheme: NavigationBarThemeData(
backgroundColor: scheme.surface,
elevation: 0,
indicatorColor: scheme.secondaryContainer,
indicatorShape: HighContrastSurfaces.rounded,
surfaceTintColor: clear,
),
drawerTheme: DrawerThemeData(
backgroundColor: scheme.surface,
surfaceTintColor: clear,
elevation: 0,
shape: Border(right: surfaces.border),
),
textSelectionTheme: TextSelectionThemeData(
cursorColor: scheme.primary,
selectionColor: scheme.primary.withValues(alpha: dark ? 0.45 : 0.3),
selectionHandleColor: scheme.primary,
),
),
surfaces,
);
}