ca2f7eee32
AppDesign builds each design's light and dark ThemeData with an AppDesignTokens extension (corner radius, flat surfaces, frame colour, ANSI accents, prompt glyph). Settings gains a Design picker stored per device; the theme hosts rebuild live. Terminal is monospace (bundled RobotoMono), near-black or paper, flat 1px frames with 3px corners, and draws the chat transcript as prompt lines, tool dot/result lines and bracketed follow-up lines. Default keeps its exact themes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
165 lines
5.0 KiB
Dart
165 lines
5.0 KiB
Dart
import 'dart:ui' show SemanticsRole;
|
|
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
|
|
import '../theme/app_design_tokens.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../motion/motion.dart';
|
|
import 'floating_tab_motion.dart';
|
|
import 'glass_pill.dart';
|
|
import 'segmented_bar_motion.dart';
|
|
|
|
/// One tab of a floating tab bar: a round [GlassPill] of [size] with the
|
|
/// tab's icon in the middle.
|
|
///
|
|
/// The selected tab fills its circle with Material `secondaryContainer`
|
|
/// and draws its icon in the selected colour; the
|
|
/// tint and colour cross-fade when the selection moves. A press sinks the
|
|
/// button ([SegmentedPress]), the Material one with its circular ink.
|
|
///
|
|
/// It is announced like the host navigation controls' tabs: a tab (and a
|
|
/// button) named by [label], with its selected state and "tab n of m"
|
|
/// in its accessible label. Material shows [label]
|
|
/// as a tooltip. The icon is painted above the glass, unclipped, so a badge
|
|
/// on its corner can reach past the circle.
|
|
class FloatingTabButton extends StatelessWidget {
|
|
const FloatingTabButton({
|
|
super.key,
|
|
required this.motion,
|
|
required this.index,
|
|
required this.count,
|
|
required this.selected,
|
|
required this.size,
|
|
required this.iconSize,
|
|
required this.label,
|
|
required this.icon,
|
|
required this.onTap,
|
|
this.enabled = true,
|
|
this.tooltip,
|
|
});
|
|
|
|
/// Shown (and given as the accessibility hint) instead of [label].
|
|
final String? tooltip;
|
|
|
|
/// False greys the tab out and ignores taps; it keeps its place.
|
|
final bool enabled;
|
|
|
|
final FloatingTabMotion motion;
|
|
final int index;
|
|
final int count;
|
|
final bool selected;
|
|
final double size;
|
|
final double iconSize;
|
|
final String label;
|
|
|
|
/// The icon for the current state (the item's selected icon when selected).
|
|
final Widget icon;
|
|
final VoidCallback onTap;
|
|
|
|
/// The selection [Ink] inside each button, for tests.
|
|
static const Key fillKey = ValueKey('floating-tab-button.fill');
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colors = _colors(context);
|
|
final duration = Motion.of(context, Motion.tabSelectDuration);
|
|
final button = TweenAnimationBuilder<double>(
|
|
tween: Tween(end: selected ? 1 : 0),
|
|
duration: duration,
|
|
curve: Motion.curve,
|
|
builder: (context, t, _) => _button(context, colors, t),
|
|
);
|
|
return MergeSemantics(
|
|
child: Semantics(
|
|
role: SemanticsRole.tab,
|
|
selected: selected,
|
|
enabled: enabled,
|
|
hint: tooltip,
|
|
button: true,
|
|
label: kIsWeb ? label : '$label\n${_tabLabel(context)}',
|
|
// Switching tabs does not unfocus a text field (the composer).
|
|
child: TextFieldTapRegion(
|
|
child: Tooltip(
|
|
message: tooltip ?? label,
|
|
excludeFromSemantics: true,
|
|
child: button,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _tabLabel(BuildContext context) => MaterialLocalizations.of(
|
|
context,
|
|
).tabLabel(tabIndex: index + 1, tabCount: count);
|
|
|
|
({Color tint, Color selectedIcon, Color icon}) _colors(BuildContext context) {
|
|
final scheme = Theme.of(context).colorScheme;
|
|
return (
|
|
tint: scheme.secondaryContainer,
|
|
selectedIcon: scheme.onSecondaryContainer,
|
|
icon: enabled
|
|
? scheme.onSurfaceVariant
|
|
: scheme.onSurface.withValues(alpha: .38),
|
|
);
|
|
}
|
|
|
|
/// The button at selection progress [t] (0 unselected, 1 selected).
|
|
Widget _button(
|
|
BuildContext context,
|
|
({Color tint, Color selectedIcon, Color icon}) colors,
|
|
double t,
|
|
) {
|
|
// A flat design (Terminal) squares the button and its fill.
|
|
final shape = AppDesignTokens.of(context).shape(const CircleBorder());
|
|
final decoration = ShapeDecoration(
|
|
color: colors.tint.withValues(alpha: colors.tint.a * t),
|
|
shape: shape,
|
|
);
|
|
final Widget fill = Ink(
|
|
key: fillKey,
|
|
decoration: decoration,
|
|
child: InkResponse(
|
|
onTap: enabled ? onTap : null,
|
|
customBorder: shape,
|
|
containedInkWell: true,
|
|
highlightShape: shape is CircleBorder
|
|
? BoxShape.circle
|
|
: BoxShape.rectangle,
|
|
),
|
|
);
|
|
Widget glyph = IconTheme.merge(
|
|
data: IconThemeData(
|
|
size: iconSize,
|
|
color: Color.lerp(colors.icon, colors.selectedIcon, t),
|
|
),
|
|
child: FloatingTabBounce(motion: motion, index: index, child: icon),
|
|
);
|
|
final reveal = GlassReveal.maybeOf(context);
|
|
if (reveal != null) {
|
|
// The icon sits above the glass, so it fades with it here.
|
|
glyph = FadeTransition(
|
|
opacity: reveal,
|
|
alwaysIncludeSemantics: true,
|
|
child: glyph,
|
|
);
|
|
}
|
|
return SegmentedPress(
|
|
child: SizedBox.square(
|
|
dimension: size,
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Positioned.fill(
|
|
child: GlassPill(shape: shape, child: fill),
|
|
),
|
|
IgnorePointer(child: glyph),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|