import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../text/monospace.dart'; import 'app_design.dart'; import 'app_design_tokens.dart'; import 'app_theme.dart'; import 'terminal_palette.dart'; /// Terminal's corner radius: square enough to read as a terminal frame, soft /// enough not to alias. const double terminalRadius = 3; const BorderRadius _corners = BorderRadius.all(Radius.circular(terminalRadius)); /// The Terminal design's theme: the bundled monospace family everywhere, /// compact text, flat surfaces with 1px dim frames and no elevation, and /// the ANSI accents as the colour roles. Every Material component the app /// uses takes the same shapes, so lists, dialogs, menus and buttons follow /// without per-widget code. ThemeData terminalTheme(Brightness brightness) { final scheme = terminalColorScheme(brightness); final ansi = brightness == Brightness.dark ? terminalDarkAnsi : terminalLightAnsi; final frame = BorderSide(color: scheme.outlineVariant); final framed = RoundedRectangleBorder(borderRadius: _corners, side: frame); const square = RoundedRectangleBorder(borderRadius: _corners); final base = ThemeData( platform: kIsWeb ? TargetPlatform.android : null, colorScheme: scheme, fontFamily: appMonospaceFamily, scaffoldBackgroundColor: scheme.surface, canvasColor: scheme.surface, pageTransitionsTheme: appPageTransitions, visualDensity: const VisualDensity(horizontal: -1, vertical: -1), splashFactory: NoSplash.splashFactory, shadowColor: const Color(0x00000000), dividerColor: scheme.outlineVariant, extensions: [ AppDesignTokens( design: AppDesign.terminal, radius: terminalRadius, flat: true, frame: scheme.outlineVariant, ansi: ansi, ), ], ); ButtonStyle buttons(ButtonStyle? style) => (style ?? const ButtonStyle()).copyWith( shape: const WidgetStatePropertyAll(square), elevation: const WidgetStatePropertyAll(0), shadowColor: const WidgetStatePropertyAll(Color(0x00000000)), ); final menu = MenuStyle( backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerLow), elevation: const WidgetStatePropertyAll(0), shadowColor: const WidgetStatePropertyAll(Color(0x00000000)), surfaceTintColor: const WidgetStatePropertyAll(Color(0x00000000)), shape: WidgetStatePropertyAll( RoundedRectangleBorder( borderRadius: _corners, side: BorderSide(color: scheme.outline), ), ), ); return base.copyWith( textTheme: terminalTextTheme(base.textTheme), primaryTextTheme: terminalTextTheme(base.primaryTextTheme), appBarTheme: AppBarTheme( backgroundColor: scheme.surface, surfaceTintColor: const Color(0x00000000), elevation: 0, scrolledUnderElevation: 0, shape: Border(bottom: frame), ), // Only the frame: each card variant (filled, outlined) keeps its own // fill, so a selected graph node still reads apart. cardTheme: CardThemeData( elevation: 0, shadowColor: const Color(0x00000000), surfaceTintColor: const Color(0x00000000), shape: framed, ), dialogTheme: DialogThemeData( backgroundColor: scheme.surfaceContainerLow, surfaceTintColor: const Color(0x00000000), elevation: 0, shape: RoundedRectangleBorder( borderRadius: _corners, side: BorderSide(color: scheme.outline), ), ), bottomSheetTheme: BottomSheetThemeData( backgroundColor: scheme.surfaceContainerLow, modalBackgroundColor: scheme.surfaceContainerLow, surfaceTintColor: const Color(0x00000000), elevation: 0, modalElevation: 0, shape: RoundedRectangleBorder( borderRadius: _corners, side: BorderSide(color: scheme.outline), ), ), popupMenuTheme: PopupMenuThemeData( color: scheme.surfaceContainerLow, surfaceTintColor: const Color(0x00000000), elevation: 0, shape: RoundedRectangleBorder( borderRadius: _corners, side: BorderSide(color: scheme.outline), ), ), menuTheme: MenuThemeData(style: menu), dropdownMenuTheme: DropdownMenuThemeData(menuStyle: menu), menuButtonTheme: MenuButtonThemeData( style: MenuItemButton.styleFrom(shape: square), ), filledButtonTheme: FilledButtonThemeData( style: buttons(base.filledButtonTheme.style), ), elevatedButtonTheme: ElevatedButtonThemeData( style: buttons(base.elevatedButtonTheme.style), ), outlinedButtonTheme: OutlinedButtonThemeData( style: buttons(base.outlinedButtonTheme.style).copyWith( side: WidgetStatePropertyAll(BorderSide(color: scheme.outline)), ), ), textButtonTheme: TextButtonThemeData( style: buttons(base.textButtonTheme.style), ), iconButtonTheme: IconButtonThemeData( style: buttons(base.iconButtonTheme.style), ), segmentedButtonTheme: SegmentedButtonThemeData( style: buttons(base.segmentedButtonTheme.style), ), floatingActionButtonTheme: FloatingActionButtonThemeData( elevation: 0, focusElevation: 0, hoverElevation: 0, highlightElevation: 0, backgroundColor: scheme.surfaceContainerHigh, foregroundColor: scheme.primary, shape: RoundedRectangleBorder( borderRadius: _corners, side: BorderSide(color: scheme.outline), ), ), chipTheme: ChipThemeData( backgroundColor: const Color(0x00000000), shape: framed, side: frame, elevation: 0, pressElevation: 0, ), // Only the base border: a field that sets `InputBorder.none` (the // composer, whose frame is its pill) keeps none in every state. inputDecorationTheme: InputDecorationTheme( isDense: true, border: OutlineInputBorder( borderRadius: _corners, borderSide: BorderSide(color: scheme.outline), ), ), searchBarTheme: SearchBarThemeData( elevation: const WidgetStatePropertyAll(0), shape: const WidgetStatePropertyAll(square), side: WidgetStatePropertyAll(BorderSide(color: scheme.outline)), backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerLow), ), navigationRailTheme: NavigationRailThemeData( backgroundColor: scheme.surface, elevation: 0, indicatorColor: scheme.primaryContainer, indicatorShape: square, ), navigationBarTheme: NavigationBarThemeData( backgroundColor: scheme.surface, elevation: 0, indicatorColor: scheme.primaryContainer, indicatorShape: square, surfaceTintColor: const Color(0x00000000), ), listTileTheme: const ListTileThemeData(shape: square), dividerTheme: DividerThemeData( color: scheme.outlineVariant, thickness: 1, space: 1, ), tabBarTheme: TabBarThemeData( dividerColor: scheme.outlineVariant, indicatorSize: TabBarIndicatorSize.tab, indicator: UnderlineTabIndicator( borderSide: BorderSide(color: scheme.primary, width: 2), ), ), snackBarTheme: SnackBarThemeData( backgroundColor: scheme.surfaceContainerHigh, contentTextStyle: TextStyle( color: scheme.onSurface, fontFamily: appMonospaceFamily, ), elevation: 0, shape: RoundedRectangleBorder( borderRadius: _corners, side: BorderSide(color: scheme.outline), ), ), tooltipTheme: TooltipThemeData( decoration: BoxDecoration( color: scheme.surfaceContainerHighest, borderRadius: _corners, border: Border.all(color: scheme.outline), ), textStyle: TextStyle( color: scheme.onSurface, fontFamily: appMonospaceFamily, fontSize: 12, ), ), scrollbarTheme: const ScrollbarThemeData(radius: Radius.zero), progressIndicatorTheme: ProgressIndicatorThemeData( color: scheme.primary, linearTrackColor: scheme.outlineVariant, ), ); } /// [base] in the monospace family at a terminal's compact size: Material's /// roles a step smaller (monospace runs wide), with no added letter spacing. TextTheme terminalTextTheme(TextTheme base) { TextStyle? mono(TextStyle? style) { if (style == null) return null; final size = style.fontSize; return style.copyWith( fontFamily: appMonospaceFamily, fontSize: size == null ? null : (size * 0.875).roundToDouble(), letterSpacing: 0, ); } return base.copyWith( displayLarge: mono(base.displayLarge), displayMedium: mono(base.displayMedium), displaySmall: mono(base.displaySmall), headlineLarge: mono(base.headlineLarge), headlineMedium: mono(base.headlineMedium), headlineSmall: mono(base.headlineSmall), titleLarge: mono(base.titleLarge), titleMedium: mono(base.titleMedium), titleSmall: mono(base.titleSmall), bodyLarge: mono(base.bodyLarge), bodyMedium: mono(base.bodyMedium), bodySmall: mono(base.bodySmall), labelLarge: mono(base.labelLarge), labelMedium: mono(base.labelMedium), labelSmall: mono(base.labelSmall), ); }