import 'package:flutter/material.dart'; import 'notebook_theme.dart'; const Color _clear = Color(0x00000000); // Kept per colour: a tab indicator and a resolver compare by identity, so // fresh ones would make a rebuilt theme unequal to the last // (test/perf/design_bench_test.dart). final Map _tabIndicators = {}; final Map<(Color, Color), WidgetStateBorderSide> _checkboxSides = {}; /// [base] with Notebook's controls: buttons, menus, chips, fields, search /// bars, tabs, segmented buttons, switches, checkboxes, sliders, badges and /// progress in [notebookRadius] corners with hairline outlines, no /// elevation and the IDE blue; fields are boxed. ThemeData notebookControls(ThemeData base, NotebookSurfaces surfaces) { final scheme = base.colorScheme; const rounded = NotebookSurfaces.rounded; ButtonStyle buttons(ButtonStyle? style) => (style ?? const ButtonStyle()).copyWith( shape: const WidgetStatePropertyAll(rounded), elevation: const WidgetStatePropertyAll(0), shadowColor: const WidgetStatePropertyAll(_clear), ); final outline = WidgetStatePropertyAll(BorderSide(color: scheme.outline)); final menu = MenuStyle( backgroundColor: WidgetStatePropertyAll(surfaces.floating), elevation: const WidgetStatePropertyAll(NotebookSurfaces.floatElevation), shadowColor: WidgetStatePropertyAll(surfaces.shadow), surfaceTintColor: const WidgetStatePropertyAll(_clear), shape: WidgetStatePropertyAll(surfaces.framed), padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 4)), ); final field = OutlineInputBorder( borderRadius: NotebookSurfaces.corners, borderSide: BorderSide(color: scheme.outlineVariant), ); return base.copyWith( menuTheme: MenuThemeData(style: menu), dropdownMenuTheme: DropdownMenuThemeData(menuStyle: menu), menuButtonTheme: MenuButtonThemeData( style: MenuItemButton.styleFrom(shape: rounded), ), filledButtonTheme: FilledButtonThemeData( style: buttons(base.filledButtonTheme.style), ), elevatedButtonTheme: ElevatedButtonThemeData( style: buttons(base.elevatedButtonTheme.style).copyWith( backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerLow), side: WidgetStatePropertyAll(surfaces.hairline), ), ), outlinedButtonTheme: OutlinedButtonThemeData( style: buttons(base.outlinedButtonTheme.style).copyWith(side: outline), ), textButtonTheme: TextButtonThemeData( style: buttons(base.textButtonTheme.style), ), iconButtonTheme: IconButtonThemeData( style: buttons(base.iconButtonTheme.style), ), segmentedButtonTheme: SegmentedButtonThemeData( style: buttons( base.segmentedButtonTheme.style, ).copyWith(side: WidgetStatePropertyAll(surfaces.hairline)), ), floatingActionButtonTheme: FloatingActionButtonThemeData( elevation: 0, focusElevation: 0, hoverElevation: 0, highlightElevation: 0, backgroundColor: scheme.surfaceContainerLow, foregroundColor: scheme.primary, shape: RoundedRectangleBorder( borderRadius: NotebookSurfaces.corners, side: BorderSide(color: scheme.outline), ), ), // A chip is a small grey tag in the cell's grey, hairline framed. chipTheme: ChipThemeData( backgroundColor: scheme.surfaceContainerLow, selectedColor: scheme.primaryContainer, shape: surfaces.framed, side: surfaces.hairline, elevation: 0, pressElevation: 0, padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2), ), // A field is a boxed cell in the design's corners. Only the base border: // a field that sets `InputBorder.none` (the composer, which draws its // own input cell) keeps none in every state. inputDecorationTheme: InputDecorationTheme(isDense: true, border: field), searchBarTheme: SearchBarThemeData( elevation: const WidgetStatePropertyAll(0), shape: const WidgetStatePropertyAll(rounded), side: WidgetStatePropertyAll(surfaces.hairline), backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerLow), surfaceTintColor: const WidgetStatePropertyAll(_clear), padding: const WidgetStatePropertyAll( EdgeInsets.symmetric(horizontal: 12), ), ), listTileTheme: const ListTileThemeData(shape: rounded), expansionTileTheme: const ExpansionTileThemeData( shape: Border(), collapsedShape: Border(), ), tabBarTheme: TabBarThemeData( dividerColor: scheme.outlineVariant, labelColor: scheme.onSurface, unselectedLabelColor: scheme.onSurfaceVariant, indicatorSize: TabBarIndicatorSize.tab, indicator: _tabIndicators[scheme.primary] ??= UnderlineTabIndicator( borderSide: BorderSide(color: scheme.primary, width: 2), ), ), checkboxTheme: CheckboxThemeData( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(3)), ), side: _checkboxSides[(scheme.primary, scheme.outline)] ??= WidgetStateBorderSide.resolveWith( (states) => states.contains(WidgetState.selected) ? BorderSide(color: scheme.primary, width: 1.5) : BorderSide(color: scheme.outline, width: 1.5), ), ), sliderTheme: SliderThemeData( trackHeight: 3, activeTrackColor: scheme.primary, inactiveTrackColor: scheme.outlineVariant, thumbColor: scheme.primary, thumbShape: const RoundSliderThumbShape( enabledThumbRadius: 7, elevation: 0, pressedElevation: 0, ), overlayShape: const RoundSliderOverlayShape(overlayRadius: 16), valueIndicatorColor: scheme.inverseSurface, valueIndicatorTextStyle: TextStyle(color: scheme.onInverseSurface), ), badgeTheme: BadgeThemeData( backgroundColor: scheme.primary, textColor: scheme.onPrimary, padding: const EdgeInsets.symmetric(horizontal: 4), ), progressIndicatorTheme: ProgressIndicatorThemeData( color: scheme.primary, linearTrackColor: scheme.outlineVariant, circularTrackColor: _clear, linearMinHeight: 2, ), scrollbarTheme: const ScrollbarThemeData( radius: Radius.circular(3), thickness: WidgetStatePropertyAll(6), ), ); }