Merge branch 'main' into pipelines/run-20261111-0323-cupertino-out-shell-eacf

# Conflicts:
#	app/test/application/search_artifact_open_test.dart
#	app/test/application/search_chat_open_test.dart
This commit is contained in:
2026-11-11 03:54:36 +00:00
36 changed files with 1107 additions and 1789 deletions
+16 -33
View File
@@ -1,14 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../core/api_gateway.dart';
import '../../shell/shell_bar.dart';
import '../../shell/shell_search_focus.dart';
import '../../ui/adaptive/host.dart';
import '../../ui/adaptive/segmented_bar.dart';
import 'data/search_repository.dart';
import 'domain/search_controller.dart';
import 'ui/cupertino_search_body.dart';
import 'ui/material_search_body.dart';
import 'ui/search_bar_controls.dart';
import 'ui/search_bounds_note.dart';
@@ -31,8 +28,7 @@ class SearchScreen extends StatefulWidget {
final ApiGateway gateway;
final ValueChanged<JsonMap> onOpen;
/// Lets the shell state the surface it composed. When omitted, iOS/macOS use
/// Cupertino controls and every other platform uses Material.
/// Retained for the shell's surface contract; search is Material-only.
final bool? cupertino;
/// True as the Search tab: the controls go into the shell's bar.
@@ -127,39 +123,33 @@ class _SearchScreenState extends State<SearchScreen> {
);
Widget _build(BuildContext context) {
// Follow the actual host app class: Cupertino only under an explicit
// Cupertino host, Material on every platform otherwise.
final cupertino = widget.cupertino ?? usesCupertinoHost(context);
if (widget.embedded) {
// The shell's bar carries the controls; without a shell (a bare embed)
// they lead the results instead.
if (!ShellBar.available(context)) {
return _body(cupertino, controls: _controls(cupertino));
return _body(controls: _controls());
}
// The field takes the title's place and fills the bar.
return ShellBar(
titleWidget: _controls(cupertino),
child: _body(cupertino),
titleWidget: _controls(),
child: _body(),
);
}
final bar = SegmentedBar(
cupertino: cupertino,
cupertino: false,
title: 'Search',
titleWidget: _controls(cupertino),
titleWidget: _controls(),
);
if (cupertino) {
return CupertinoPageScaffold(navigationBar: bar, child: _body(cupertino));
}
return Scaffold(
extendBodyBehindAppBar: true,
appBar: bar,
body: _body(cupertino),
body: _body(),
);
}
Widget _controls(bool cupertino) => SearchBarControls(
Widget _controls() => SearchBarControls(
focusNode: _focus,
cupertino: cupertino,
cupertino: false,
text: _text,
kind: _controller.parsed.kind,
onChanged: _controller.updateQuery,
@@ -189,24 +179,17 @@ class _SearchScreenState extends State<SearchScreen> {
/// No top safe area: the results run behind the floating bar and the
/// scroll view starts them below it.
Widget _body(bool cupertino, {Widget? controls}) {
Widget _body({Widget? controls}) {
final header = _header(controls: controls);
return SearchArtifactScope(
gateway: widget.gateway,
onOpen: widget.onOpen,
child: cupertino
? CupertinoSearchBody(
controller: _controller,
query: _controller.parsed.query,
onOpen: widget.onOpen,
header: header,
)
: MaterialSearchBody(
controller: _controller,
query: _controller.parsed.query,
onOpen: widget.onOpen,
header: header,
),
child: MaterialSearchBody(
controller: _controller,
query: _controller.parsed.query,
onOpen: widget.onOpen,
header: header,
),
);
}
}
@@ -1,142 +0,0 @@
import 'package:flutter/cupertino.dart';
import '../../../core/api_gateway.dart';
import '../domain/search_controller.dart';
import 'search_result_slivers.dart';
import 'search_layout.dart';
/// The Cupertino search view: an optional status header and the shared list
/// rows in one scroll view that runs behind the top bar, with standard
/// activity and retry controls.
class CupertinoSearchBody extends StatelessWidget {
const CupertinoSearchBody({
super.key,
required this.controller,
required this.query,
required this.onOpen,
required this.header,
});
final OmniSearchController controller;
final String query;
final ValueChanged<JsonMap> onOpen;
final Widget header;
@override
Widget build(BuildContext context) {
return SearchScrollView(
slivers: [
SliverToBoxAdapter(child: header),
if (controller.showProgress)
const SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: CupertinoActivityIndicator(),
),
),
..._content(context),
],
);
}
List<Widget> _content(BuildContext context) {
switch (controller.bodyKind) {
case SearchBodyKind.error:
return [
SliverFillRemaining(
hasScrollBody: false,
child: _CupertinoError(
message: controller.error!,
onRetry: controller.retry,
),
),
];
case SearchBodyKind.searching:
return const [
SliverFillRemaining(
hasScrollBody: false,
child: _CupertinoSearching(),
),
];
case SearchBodyKind.results:
return searchResultSlivers(
controller: controller,
query: query,
onOpen: onOpen,
cupertino: true,
message: (text) => _CupertinoMessage(message: text),
);
case SearchBodyKind.empty:
return [
SliverToBoxAdapter(
child: _CupertinoMessage(message: controller.emptyMessage!),
),
];
case SearchBodyKind.idle:
return const [
SliverFillRemaining(
hasScrollBody: false,
child: _CupertinoMessage(
message: 'Search pipelines, runs, artifacts and chats.',
),
),
];
}
}
}
class _CupertinoSearching extends StatelessWidget {
const _CupertinoSearching();
@override
Widget build(BuildContext context) => const Center(
child: Padding(
padding: EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
spacing: 12,
children: [CupertinoActivityIndicator(), Text('Searching…')],
),
),
);
}
class _CupertinoMessage extends StatelessWidget {
const _CupertinoMessage({required this.message});
final String message;
@override
Widget build(BuildContext context) => Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Text(message, textAlign: TextAlign.center),
),
);
}
class _CupertinoError extends StatelessWidget {
const _CupertinoError({required this.message, required this.onRetry});
final String message;
final Future<void> Function() onRetry;
@override
Widget build(BuildContext context) => Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
spacing: 12,
children: [
Text(message, textAlign: TextAlign.center),
CupertinoButton.filled(
key: const ValueKey('search.retry'),
onPressed: onRetry,
child: const Text('Retry'),
),
],
),
),
);
}
@@ -59,7 +59,7 @@ class SearchBarControls extends StatelessWidget {
autofocus: autofocus,
focusNode: focusNode,
inBar: true,
cupertino: cupertino,
cupertino: false,
placeholder: 'Search pipelines, runs, artifacts and chats',
onChanged: onChanged,
onSubmitted: (_) => onSubmitted(),
@@ -67,14 +67,14 @@ class SearchBarControls extends StatelessWidget {
),
),
),
SearchKindButton(cupertino: cupertino, kind: kind, onSelected: onKind),
SearchKindButton(cupertino: false, kind: kind, onSelected: onKind),
BarIconButton(
key: searchHelpKey,
cupertino: cupertino,
cupertino: false,
icon: Icons.info_outline,
cupertinoIcon: CupertinoIcons.info_circle,
label: 'Search syntax',
onPressed: () => showSearchHelp(context, cupertino: cupertino),
onPressed: () => showSearchHelp(context, cupertino: false),
),
],
),
@@ -100,31 +100,6 @@ class SearchKindButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final narrowed = kind != SearchKind.all;
if (cupertino) {
final icon = Icon(
narrowed
? CupertinoIcons.line_horizontal_3_decrease_circle_fill
: CupertinoIcons.line_horizontal_3_decrease_circle,
);
return Semantics(
button: true,
label: _label,
excludeSemantics: true,
child: CupertinoButton(
key: searchKindKey,
padding: EdgeInsets.symmetric(horizontal: narrowed ? 8 : 0),
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
onPressed: () => _pickCupertino(context),
child: narrowed
? Row(
mainAxisSize: MainAxisSize.min,
spacing: 4,
children: [icon, Text(kind.label)],
)
: icon,
),
);
}
return PopupMenuButton<SearchKind>(
key: searchKindKey,
tooltip: _label,
@@ -153,49 +128,10 @@ class SearchKindButton extends StatelessWidget {
),
);
}
Future<void> _pickCupertino(BuildContext context) async {
final selected = await showCupertinoModalPopup<SearchKind>(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('Kind'),
actions: [
for (final value in SearchKind.values)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context, value),
isDefaultAction: value == kind,
child: Text(value.label),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
if (selected != null) onSelected(selected);
}
}
/// The query syntax, on demand instead of a paragraph above the results.
Future<void> showSearchHelp(BuildContext context, {required bool cupertino}) {
if (cupertino) {
return showCupertinoDialog<void>(
context: context,
barrierDismissible: true,
builder: (context) => CupertinoAlertDialog(
title: const Text('Search syntax'),
content: const Text(searchTokenHint),
actions: [
CupertinoDialogAction(
isDefaultAction: true,
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
return showDialog<void>(
context: context,
builder: (context) => AlertDialog(
@@ -1,8 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
const searchBoundsKey = ValueKey<String>('search.bounds');
/// The server's note that a result set was cut short, in the host's muted
@@ -14,22 +11,11 @@ class SearchBoundsNote extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final TextStyle? style;
final IconData icon;
if (cupertino) {
icon = CupertinoIcons.info_circle;
style = CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 13,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
} else {
icon = Icons.info_outline;
final theme = Theme.of(context);
style = theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
);
}
const icon = Icons.info_outline;
final theme = Theme.of(context);
final style = theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Row(
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
@@ -36,16 +35,12 @@ class SearchResultRow extends StatelessWidget {
final kind = '${hit['kind'] ?? ''}';
return AppListRow(
key: ValueKey('search.result.${hit['target']}'),
cupertino: cupertino,
cupertino: false,
divider: divider,
onTap: row.openable ? () => onOpen(hit) : null,
leading:
searchArtifactThumbnail(context, hit) ??
AppListAvatar(
child: Icon(
cupertino ? searchCupertinoIcon(kind) : searchMaterialIcon(kind),
),
),
AppListAvatar(child: Icon(searchMaterialIcon(kind))),
title: Text(row.title),
time: row.recency,
subtitle: kind == 'chat' && row.snippet != null
@@ -109,14 +104,3 @@ IconData searchMaterialIcon(String kind) => switch (kind) {
'chat' => Icons.chat_bubble_outline,
_ => Icons.help_outline,
};
IconData searchCupertinoIcon(String kind) => switch (kind) {
'pipeline' => CupertinoIcons.arrow_branch,
'version' => CupertinoIcons.square_stack_3d_up,
'run' => CupertinoIcons.play_circle,
'step' => CupertinoIcons.arrow_right,
'field' => CupertinoIcons.doc_text,
'artifact' => CupertinoIcons.paperclip,
'chat' => CupertinoIcons.chat_bubble,
_ => CupertinoIcons.question_circle,
};
@@ -32,7 +32,7 @@ List<Widget> searchResultSlivers({
hit: hits[index],
query: query,
onOpen: onOpen,
cupertino: cupertino,
cupertino: false,
divider: index < hits.length - 1,
),
);
+41 -9
View File
@@ -75,22 +75,54 @@ String windowFrameKey(String kind, String? serverKey, String contentId) =>
'$kind\n${serverKey ?? ''}\n$contentId';
/// [rect] moved and shrunk to fit inside [bounds], at least [minSize] where
/// the bounds allow it.
/// the bounds allow it, on whole logical pixels.
///
/// Whole pixels keep a moved window exactly its size from frame to frame: a
/// `Rect` stores left, top, right and bottom, so shifting a frame by a
/// fractional delta makes its width differ in its last bits, and every widget
/// that reads the window's size (its `MediaQuery`) rebuilds and lays out
/// again on every pointer event.
Rect fitWindowFrame(Rect rect, Size bounds, Size minSize) {
final width = rect.width
.clamp(minSize.width, double.infinity)
.clamp(0.0, bounds.width);
final height = rect.height
.clamp(minSize.height, double.infinity)
.clamp(0.0, bounds.height);
final width = _wholePixel(
rect.width.clamp(minSize.width, double.infinity).clamp(0.0, bounds.width),
minSize.width,
bounds.width,
);
final height = _wholePixel(
rect.height
.clamp(minSize.height, double.infinity)
.clamp(0.0, bounds.height),
minSize.height,
bounds.height,
);
return Rect.fromLTWH(
rect.left.clamp(0.0, bounds.width - width),
rect.top.clamp(0.0, bounds.height - height),
_wholePixel(
rect.left.clamp(0.0, bounds.width - width),
0,
bounds.width - width,
),
_wholePixel(
rect.top.clamp(0.0, bounds.height - height),
0,
bounds.height - height,
),
width,
height,
);
}
/// [value] rounded to a whole logical pixel and kept within
/// `[minimum, limit]`.
///
/// A fractional [minimum] rounds up, so the whole-pixel size never drops below
/// the minimum the caller asked for; when the limit is too small to hold that,
/// the limit wins.
double _wholePixel(double value, double minimum, double limit) {
final max = limit.floorToDouble();
final min = minimum.ceilToDouble().clamp(0.0, max);
return value.roundToDouble().clamp(min, max);
}
/// Where [entry] is drawn inside [bounds]: fitted, or filling the area less
/// a margin when maximised.
Rect drawnWindowFrame(WindowEntry entry, Size bounds, Size minSize) =>
+42 -8
View File
@@ -106,12 +106,26 @@ class _WindowLayerState extends State<WindowLayer>
/// Where the pointer is in the host while the title is dragged.
Offset? _pointer;
/// The frame the current move or resize started from and the pointer delta
/// summed since. Every event sets the frame from `start + total`: fitting
/// one fractional step after another would round part of the pointer's
/// movement away each time and drift, and shifting the fitted frame would
/// change its size in its last bits.
Rect? _dragStart;
Offset _dragTotal = Offset.zero;
void _move(Offset delta, Offset globalPosition) {
final box = context.findRenderObject();
_pointer = box is RenderBox ? box.globalToLocal(globalPosition) : null;
final start = _dragStart ??= _current;
_dragTotal += delta;
widget.manager.setFrame(
_id,
fitWindowFrame(_current.shift(delta), widget.bounds, widget.kind.minSize),
fitWindowFrame(
start.shift(_dragTotal),
widget.bounds,
widget.kind.minSize,
),
save: false,
);
}
@@ -121,6 +135,7 @@ class _WindowLayerState extends State<WindowLayer>
void _moveEnded() {
final pointer = _pointer;
_pointer = null;
_endDrag();
final bounds = widget.bounds;
final snap = pointer == null ? null : windowSnapFor(pointer, bounds);
if (snap == WindowSnap.maximize) {
@@ -145,15 +160,16 @@ class _WindowLayerState extends State<WindowLayer>
}
void _resize(Offset delta) {
final rect = _current;
final start = _dragStart ??= _current;
_dragTotal += delta;
widget.manager.setFrame(
_id,
fitWindowFrame(
Rect.fromLTWH(
rect.left,
rect.top,
rect.width + delta.dx,
rect.height + delta.dy,
start.left,
start.top,
start.width + _dragTotal.dx,
start.height + _dragTotal.dy,
),
widget.bounds,
widget.kind.minSize,
@@ -162,16 +178,34 @@ class _WindowLayerState extends State<WindowLayer>
);
}
void _resizeEnded() {
_endDrag();
widget.manager.commit(_id);
}
/// A drag ends here even if it is cancelled or another gesture begins.
void _endDrag() {
_dragStart = null;
_dragTotal = Offset.zero;
}
/// A press brings the window to the top and gives it the keyboard at
/// once, before the press does anything else (focus a field, open a
/// popup that takes the keyboard itself).
void _pressed() {
// A new gesture measures from where it starts, even if the last drag was
// cancelled before it ended.
_endDrag();
if (!widget.focus.has(_id)) widget.focus.focusNow(_id);
widget.manager.raise(_id);
}
ThemeData _pageThemeFor(ThemeData theme) {
if (identical(theme, _themeSource)) return _pageTheme!;
// Equal to the last theme means the same page theme, even when the app's
// animated theme hands over a new but equal `ThemeData` object: a new
// page theme would notify every content widget that reads the theme on
// every frame of a move.
if (theme == _themeSource) return _pageTheme!;
_themeSource = theme;
return _pageTheme = WindowNavigator.themeData(theme);
}
@@ -263,7 +297,7 @@ class _WindowLayerState extends State<WindowLayer>
bottom: widget.bounds.height - frame.bottom,
child: WindowResizeCorner(
onResize: _resize,
onResizeEnd: () => manager.commit(_id),
onResizeEnd: _resizeEnded,
),
),
],
+5 -37
View File
@@ -1,17 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
import 'cupertino_web_search_field.dart';
/// The app's one search field per platform.
/// The app's one search field.
///
/// Cupertino uses the stock [CupertinoSearchTextField]. Material uses a
/// [TextField] shaped like it: a stadium with a leading search icon, a clear
/// button once there is text, no underline and no elevation. On a page it is
/// filled with the host's raised surface; [inBar] drops the fill (and the
/// Cupertino grey) because a bar's glass pill is already its background.
/// A [TextField] shaped like the stock iOS field: a stadium with a leading
/// search icon, a clear button once there is text, no underline and no
/// elevation. On a page it is filled with the host's raised surface; [inBar]
/// drops the fill because a bar's glass pill is already its background.
class AppSearchField extends StatelessWidget {
const AppSearchField({
super.key,
@@ -58,32 +52,6 @@ class AppSearchField extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (cupertino ?? usesCupertinoHost(context)) {
if (kIsWeb) {
return CupertinoWebSearchField(
controller: controller,
placeholder: placeholder,
fieldKey: fieldKey,
focusNode: focusNode,
autofocus: autofocus,
inBar: inBar,
onChanged: onChanged,
onSubmitted: onSubmitted,
onCleared: _clear,
);
}
return CupertinoSearchTextField(
key: fieldKey,
controller: controller,
focusNode: focusNode,
autofocus: autofocus,
placeholder: placeholder,
backgroundColor: inBar ? const Color(0x00000000) : null,
onChanged: onChanged,
onSubmitted: onSubmitted,
onSuffixTap: _clear,
);
}
final scheme = Theme.of(context).colorScheme;
const radius = BorderRadius.all(Radius.circular(28));
const stadium = OutlineInputBorder(
@@ -1,115 +0,0 @@
import 'package:flutter/cupertino.dart';
/// Keeps the web input's semantics stable when its clear action appears.
/// Nesting the clear button in CupertinoSearchTextField changes its merged
/// editable node into a disabled child node on web. Native sibling controls
/// retain both an enabled input and an independently accessible clear action.
class CupertinoWebSearchField extends StatefulWidget {
const CupertinoWebSearchField({
super.key,
required this.controller,
required this.placeholder,
required this.onCleared,
this.fieldKey,
this.focusNode,
this.autofocus = false,
this.inBar = false,
this.onChanged,
this.onSubmitted,
});
final TextEditingController controller;
final String placeholder;
final VoidCallback onCleared;
final Key? fieldKey;
final FocusNode? focusNode;
final bool autofocus;
final bool inBar;
final ValueChanged<String>? onChanged;
final ValueChanged<String>? onSubmitted;
@override
State<CupertinoWebSearchField> createState() =>
_CupertinoWebSearchFieldState();
}
class _CupertinoWebSearchFieldState extends State<CupertinoWebSearchField> {
FocusNode? _localFocus;
FocusNode get _focus => widget.focusNode ?? (_localFocus ??= FocusNode());
void _clear() {
final focus = _focus;
// The browser can keep the old editing session focused on the semantic
// clear button after it is removed. This explicit action ends that edit,
// then hands focus back after layout; ordinary query changes never refocus.
focus.unfocus();
widget.onCleared();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted || !identical(focus, _focus)) return;
final current = FocusManager.instance.primaryFocus;
if (current == null || current == focus || current is FocusScopeNode) {
focus.requestFocus();
}
});
WidgetsBinding.instance.ensureVisualUpdate();
}
@override
void dispose() {
_localFocus?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => DecoratedBox(
decoration: BoxDecoration(
color: widget.inBar
? const Color(0x00000000)
: CupertinoColors.tertiarySystemFill.resolveFrom(context),
borderRadius: BorderRadius.circular(9),
),
child: ConstrainedBox(
constraints: const BoxConstraints(
minHeight: kMinInteractiveDimensionCupertino,
),
child: TextFieldTapRegion(
child: Row(
children: [
Expanded(
child: CupertinoSearchTextField(
key: widget.fieldKey,
controller: widget.controller,
focusNode: _focus,
autofocus: widget.autofocus,
placeholder: widget.placeholder,
backgroundColor: const Color(0x00000000),
suffixMode: OverlayVisibilityMode.never,
onChanged: widget.onChanged,
onSubmitted: widget.onSubmitted,
),
),
ValueListenableBuilder<TextEditingValue>(
valueListenable: widget.controller,
builder: (context, value, _) => value.text.isEmpty
? const SizedBox.shrink()
: CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 8),
onPressed: _clear,
child: Icon(
CupertinoIcons.clear_thick_circled,
color: CupertinoColors.secondaryLabel.resolveFrom(
context,
),
size: 20,
semanticLabel: CupertinoLocalizations.of(
context,
).clearButtonLabel,
),
),
),
],
),
),
),
);
}
@@ -1,6 +1,3 @@
import 'dart:math' as math;
import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
@@ -21,10 +18,9 @@ abstract interface class ContainerTransformGestureRoute
void endSwipeBack(double velocity);
}
/// The back gestures of a page that shrinks into its item: on a Cupertino
/// host the native swipe from the start edge; on Android the system's
/// predictive back. Either one drives the page's own animation, so the
/// shrink follows the finger, and releasing commits or cancels it.
/// The back gestures of a page that shrinks into its item: the system's
/// predictive back drives the page's own animation, so the shrink follows
/// the finger, and releasing commits or cancels it.
class ContainerTransformBackGestures extends StatelessWidget {
const ContainerTransformBackGestures({
super.key,
@@ -38,96 +34,8 @@ class ContainerTransformBackGestures extends StatelessWidget {
final Widget child;
@override
Widget build(BuildContext context) => cupertino
? _EdgeSwipeBack(route: route, child: child)
: _PredictiveBack(route: route, child: child);
}
/// The width of the start edge that takes a swipe back, as in iOS.
const double _edgeWidth = 20;
class _EdgeSwipeBack extends StatefulWidget {
const _EdgeSwipeBack({required this.route, required this.child});
final ContainerTransformGestureRoute route;
final Widget child;
@override
State<_EdgeSwipeBack> createState() => _EdgeSwipeBackState();
}
class _EdgeSwipeBackState extends State<_EdgeSwipeBack> {
late final HorizontalDragGestureRecognizer _recognizer =
HorizontalDragGestureRecognizer(debugOwner: this)
..onStart = _start
..onUpdate = _update
..onEnd = _end
..onCancel = _cancel;
bool _dragging = false;
@override
void dispose() {
_recognizer.dispose();
if (_dragging) widget.route.endSwipeBack(0);
super.dispose();
}
double _logical(double value) =>
Directionality.of(context) == TextDirection.rtl ? -value : value;
void _start(DragStartDetails details) {
_dragging = true;
widget.route.startSwipeBack();
}
void _update(DragUpdateDetails details) {
if (!_dragging) return;
widget.route.updateSwipeBack(
_logical(details.primaryDelta! / context.size!.width),
);
}
void _end(DragEndDetails details) {
if (!_dragging) return;
_dragging = false;
widget.route.endSwipeBack(
_logical(details.velocity.pixelsPerSecond.dx / context.size!.width),
);
}
void _cancel() {
if (!_dragging) return;
_dragging = false;
widget.route.endSwipeBack(0);
}
@override
Widget build(BuildContext context) {
final padding = MediaQuery.paddingOf(context);
final notch = Directionality.of(context) == TextDirection.rtl
? padding.right
: padding.left;
return Stack(
fit: StackFit.passthrough,
children: [
widget.child,
PositionedDirectional(
start: 0,
top: 0,
bottom: 0,
width: math.max(notch, _edgeWidth),
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
if (widget.route.backGestureEnabled) {
_recognizer.addPointer(event);
}
},
),
),
],
);
}
Widget build(BuildContext context) =>
_PredictiveBack(route: route, child: child);
}
/// Forwards Android's predictive back to the page, as the stock Material
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'container_transform_flight.dart';
@@ -15,10 +14,9 @@ const Duration _droppedSwipeDuration = Duration(milliseconds: 350);
/// [link] resolves the item each time the page animates, so closing after
/// another item took the page shrinks into that one. When the item is not on
/// screen, or the system asks for reduced motion, the page fades instead.
/// The list behind stays put. A Cupertino host keeps the native swipe back
/// from the start edge and Android its predictive back; both drive the
/// shrink with the finger. The animation-speed setting scales every
/// duration through the scheduler clock.
/// The list behind stays put. Android's predictive back drives the shrink
/// with the finger. The animation-speed setting scales every duration
/// through the scheduler clock.
class ContainerTransformPageRoute<T> extends PageRoute<T>
implements ContainerTransformGestureRoute {
ContainerTransformPageRoute({
@@ -81,33 +79,16 @@ class ContainerTransformPageRoute<T> extends PageRoute<T>
Widget child,
) {
final reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
final pageColor = cupertino
? CupertinoDynamicColor.resolve(
CupertinoTheme.of(context).scaffoldBackgroundColor,
context,
)
: Theme.of(context).scaffoldBackgroundColor;
Widget page = ContainerTransformFlight(
final page = ContainerTransformFlight(
animation: animation,
origin: reduced ? null : link.resolve,
closing: () =>
animation.status == AnimationStatus.reverse || popGestureInProgress,
tracking: () => popGestureInProgress,
pageColor: pageColor,
scrimColor: cupertino
? CupertinoColors.black
: Theme.of(context).colorScheme.scrim,
pageColor: Theme.of(context).scaffoldBackgroundColor,
scrimColor: Theme.of(context).colorScheme.scrim,
child: child,
);
if (cupertino) {
// A page pushed over this one keeps the native parallax.
page = CupertinoPageTransition(
primaryRouteAnimation: kAlwaysCompleteAnimation,
secondaryRouteAnimation: secondaryAnimation,
linearTransition: popGestureInProgress,
child: page,
);
}
return ContainerTransformBackGestures(
route: this,
cupertino: cupertino,
+7 -30
View File
@@ -1,14 +1,10 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// One icon action of a segmented bar's actions pill (or any toolbar row).
///
/// Every action gets the platform's whole touch target and no extra padding,
/// so a row of them is evenly spaced and the last one never touches the
/// pill's edge: Material's [IconButton] (48dp, with its tooltip), Cupertino's
/// [CupertinoButton] at [kMinInteractiveDimensionCupertino] (44pt) square.
/// pill's edge: Material's [IconButton] (48dp, with its tooltip).
/// While [busy] the action shows the platform's activity indicator in the
/// same box and takes no taps.
class BarIconButton extends StatelessWidget {
@@ -43,40 +39,21 @@ class BarIconButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final native = cupertino ?? usesCupertinoHost(context);
if (busy) {
final side = native
? kMinInteractiveDimensionCupertino
: kMinInteractiveDimension;
return Semantics(
label: busyLabel ?? label,
liveRegion: true,
child: SizedBox.square(
dimension: side,
child: const SizedBox.square(
dimension: kMinInteractiveDimension,
child: Center(
child: native
? const CupertinoActivityIndicator()
: const SizedBox.square(
dimension: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
child: SizedBox.square(
dimension: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
),
);
}
if (native) {
return Semantics(
button: true,
label: label,
excludeSemantics: true,
child: CupertinoButton(
padding: EdgeInsets.zero,
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
onPressed: onPressed,
child: Icon(cupertinoIcon),
),
);
}
return IconButton(
tooltip: label,
isSelected: selected,
+1 -24
View File
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/glass_bar.dart';
import '../adaptive/host.dart';
/// Previous and next as chevrons in one row at the bottom right, with the
/// position before them (`2 of 5`). Each chevron is named for assistive
@@ -34,33 +32,12 @@ class ChevronPager extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
Widget chevron({
required Key? key,
required bool previous,
required String label,
required VoidCallback? onPressed,
}) {
if (cupertino) {
return Semantics(
button: true,
enabled: onPressed != null,
label: label,
excludeSemantics: true,
child: CupertinoButton(
key: key,
padding: EdgeInsets.zero,
minimumSize: GlassBarMetrics.cupertinoMinimumSize(),
onPressed: onPressed,
child: Icon(
previous
? CupertinoIcons.chevron_left
: CupertinoIcons.chevron_right,
size: GlassBarMetrics.iconSize(true),
),
),
);
}
return IconButton(
key: key,
tooltip: label,
@@ -77,7 +54,7 @@ class ChevronPager extends StatelessWidget {
// The surrounding glass bar supplies the edge gap ([GlassBarMetrics]).
// The position keeps an icon's inset on each side, so it sits as far from
// the bar's edge and from the chevrons as an icon would.
final inset = GlassBarMetrics.iconInset(cupertino);
final inset = GlassBarMetrics.iconInset(false);
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
-16
View File
@@ -37,7 +37,6 @@ ThemeData appLightTheme({String? fontFamily}) {
colorScheme: scheme,
pageTransitionsTheme: appPageTransitions,
fontFamily: fontFamily,
cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme),
);
}
@@ -110,7 +109,6 @@ ThemeData appDarkTheme({String? fontFamily}) {
scaffoldBackgroundColor: scheme.surface,
pageTransitionsTheme: appPageTransitions,
fontFamily: fontFamily,
cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme),
);
}
@@ -146,17 +144,3 @@ CupertinoTextThemeData appCupertinoTextTheme(
dateTimePickerTextStyle: face(base.dateTimePickerTextStyle),
);
}
/// Cupertino widgets on a Material host derive their theme from Material's;
/// only the family is overridden, with Material's primary for actions.
NoDefaultCupertinoThemeData? _cupertinoOverride(
String? fontFamily,
ColorScheme scheme,
) => fontFamily == null
? null
: CupertinoThemeData(
textTheme: appCupertinoTextTheme(
fontFamily,
primaryColor: scheme.primary,
),
);