feat(app): an open run takes over the app bar (Back, run, more menu); Search is the fifth tab; tabs keep their last screen

This commit is contained in:
2026-10-23 17:47:05 +01:00
parent 30e3f22a1c
commit 14a556ebd9
13 changed files with 606 additions and 289 deletions
+6 -4
View File
@@ -56,8 +56,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
_searchReturn = initial.kind == AppRouteKind.search _searchReturn = initial.kind == AppRouteKind.search
? AppRoute.pipelines ? AppRoute.pipelines
: initial, : initial,
_templatesReturn = initial.kind == AppRouteKind.templates _templatesReturn =
|| initial.kind == AppRouteKind.schedules initial.kind == AppRouteKind.templates ||
initial.kind == AppRouteKind.schedules
? AppRoute.settings ? AppRoute.settings
: initial; : initial;
@@ -111,7 +112,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
/// The route the shell renders underneath the transient Search, Templates /// The route the shell renders underneath the transient Search, Templates
/// and Schedules pages. Those pages keep the shell mounted, so the route the /// and Schedules pages. Those pages keep the shell mounted, so the route the
/// operator last opened there is still the shell's own destination. /// operator last opened there is still the shell's own destination.
AppRoute get shellRoute => searchOpen AppRoute get shellRoute => searchOpen && searchBuilder != null
? _searchReturn ? _searchReturn
: templatesOpen || schedulesOpen : templatesOpen || schedulesOpen
? _templatesReturn ? _templatesReturn
@@ -256,7 +257,8 @@ RouteInformation initialRouteInformation() {
if (!kIsWeb) { if (!kIsWeb) {
// A cold start from a deep link carries the full link as the platform's // A cold start from a deep link carries the full link as the platform's
// initial route; an ordinary launch opens the Pipelines list. // initial route; an ordinary launch opens the Pipelines list.
final launched = WidgetsBinding.instance.platformDispatcher.defaultRouteName; final launched =
WidgetsBinding.instance.platformDispatcher.defaultRouteName;
return RouteInformation( return RouteInformation(
uri: launched.isEmpty || launched == '/' uri: launched.isEmpty || launched == '/'
? Uri(path: '/pipelines') ? Uri(path: '/pipelines')
+94 -77
View File
@@ -2,7 +2,6 @@ import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import '../core/api_gateway.dart'; import '../core/api_gateway.dart';
@@ -149,12 +148,13 @@ class _PipelinesAppState extends State<PipelinesApp>
cupertino: _cupertino, cupertino: _cupertino,
onPopToRuns: () => _delegate.goTo(AppRoute.runs), onPopToRuns: () => _delegate.goTo(AppRoute.runs),
onPopToChat: () => _delegate.goTo(AppRoute.chat), onPopToChat: () => _delegate.goTo(AppRoute.chat),
searchBuilder: _buildSearch,
templatesBuilder: _buildTemplates, templatesBuilder: _buildTemplates,
schedulesBuilder: _buildSchedules, schedulesBuilder: _buildSchedules,
builder: _buildShell, builder: _buildShell,
); );
_delegate.addListener(_routeChanged); _delegate.addListener(_routeChanged);
_tabRoutes[_destinationOf(_delegate.shellRoute.kind)] =
_delegate.shellRoute;
_chatQuestionNotices = ChatQuestionNotices( _chatQuestionNotices = ChatQuestionNotices(
gateway: _session.gateway, gateway: _session.gateway,
canNotify: () => _notifications.canNotify, canNotify: () => _notifications.canNotify,
@@ -264,19 +264,6 @@ class _PipelinesAppState extends State<PipelinesApp>
Widget build(BuildContext context) => Widget build(BuildContext context) =>
MyApp.router(cupertino: _cupertino, routerConfig: _config); MyApp.router(cupertino: _cupertino, routerConfig: _config);
/// The transient Search page. Escape matches the browser's panel shortcut;
/// the native Back button and browser Back come from the router and page.
Widget _buildSearch(BuildContext context) => CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.escape): _delegate.closeSearch,
},
child: SearchDestination(
session: _session,
server: widget.server,
onOpen: _openSearchResult,
),
);
/// Open a result through the exact identity the hit records. An unresolvable /// Open a result through the exact identity the hit records. An unresolvable
/// hit navigates nowhere: the screen already presents it read-only rather than /// hit navigates nowhere: the screen already presents it read-only rather than
/// guessing a destination. /// guessing a destination.
@@ -336,7 +323,21 @@ class _PipelinesAppState extends State<PipelinesApp>
/// a failed detail, would otherwise keep the request for the next unrelated /// a failed detail, would otherwise keep the request for the next unrelated
/// visit to the same run. Search/Templates/Schedules pages above the run keep /// visit to the same run. Search/Templates/Schedules pages above the run keep
/// it, because the shell route underneath them still names that run. /// it, because the shell route underneath them still names that run.
/// The last route each tab showed, so switching tabs returns to where the
/// operator left it; tapping the open tab again goes to its root.
final Map<AppDestination, AppRoute> _tabRoutes = {};
void _selectDestination(AppDestination destination) {
final current = _destinationOf(_delegate.shellRoute.kind);
final last = _tabRoutes[destination];
_delegate.goTo(
destination == current || last == null ? _routeOf(destination) : last,
);
}
void _routeChanged() { void _routeChanged() {
final shown = _delegate.shellRoute;
_tabRoutes[_destinationOf(shown.kind)] = shown;
final pending = _pendingRunSearch; final pending = _pendingRunSearch;
if (!mounted || pending == null) return; if (!mounted || pending == null) return;
final route = _delegate.shellRoute; final route = _delegate.shellRoute;
@@ -397,76 +398,91 @@ class _PipelinesAppState extends State<PipelinesApp>
builder: (context, count, _) => _shellFor(route, count), builder: (context, count, _) => _shellFor(route, count),
); );
Widget _shellFor(AppRoute route, int attentionCount) => AdaptiveShell( Widget _shellFor(AppRoute route, int attentionCount) {
attentionCount: attentionCount, // Each tab is built from the route it last showed, so switching tabs keeps
cupertino: _cupertino, // an open run, pipeline or chat instead of resetting it.
destination: _destinationOf(route.kind), AppRoute tab(AppDestination destination) =>
onDestinationSelected: (destination) => _destinationOf(route.kind) == destination
_delegate.goTo(_routeOf(destination)), ? route
onSearch: _delegate.openSearch, : _tabRoutes[destination] ?? _routeOf(destination);
destinationBodies: { final pipelinesRoute = tab(AppDestination.pipelines);
AppDestination.pipelines: (_) => PipelinesDestination( final runsRoute = tab(AppDestination.runs);
session: _session, final chatRoute = tab(AppDestination.chat);
server: widget.server, return AdaptiveShell(
refreshToken: _pipelinesRefresh, attentionCount: attentionCount,
onRunStarted: _runStarted, cupertino: _cupertino,
onViewPipelineRuns: (id) => destination: _destinationOf(route.kind),
_delegate.goTo(AppRoute.runsForPipeline(id)), onDestinationSelected: _selectDestination,
initialPipelineId: route.pipelineId, destinationBodies: {
initialVersion: route.version, AppDestination.pipelines: (_) => PipelinesDestination(
initialStageKey: route.stageKey,
),
// The one place a field or artifact hit's selection can be resolved: the
// run detail owns the recorded visit and Summary section.
AppDestination.runs: (_) => RunSearchSelectionScope(
selection: _pendingRunSearch,
onConsumed: _runSearchConsumed,
child: RunsDestination(
session: _session, session: _session,
server: widget.server, server: widget.server,
initialRunId: route.runId, refreshToken: _pipelinesRefresh,
initialPipelineId: route.pipelineId, onRunStarted: _runStarted,
initialStageKey: route.stageKey, onViewPipelineRuns: (id) =>
initialVisit: route.visit, _delegate.goTo(AppRoute.runsForPipeline(id)),
initialDecide: route.decide, initialPipelineId: pipelinesRoute.pipelineId,
listRefreshToken: _runsRefresh, initialVersion: pipelinesRoute.version,
notifications: _notifications, initialStageKey: pipelinesRoute.stageKey,
attention: _attention,
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
onBack: (id) => _delegate.goTo(
id == null ? AppRoute.runs : AppRoute.runsForPipeline(id),
),
onPipelineFilterChanged: (id) => _delegate.goTo(
id == null ? AppRoute.runs : AppRoute.runsForPipeline(id),
),
onOpenPipeline: (id, version) =>
_delegate.goTo(AppRoute.pipeline(id, version: version)),
), ),
), // The one place a field or artifact hit's selection can be resolved: the
AppDestination.chat: (_) => ChatDestination( // run detail owns the recorded visit and Summary section.
session: _session, AppDestination.runs: (_) => RunSearchSelectionScope(
server: widget.server, selection: _pendingRunSearch,
initialSessionId: route.chatSessionId, onConsumed: _runSearchConsumed,
onSessionSelected: (id) => _delegate.goTo(AppRoute.chatSession(id)), child: RunsDestination(
onBack: () => _delegate.goTo(AppRoute.chat), session: _session,
), server: widget.server,
AppDestination.settings: (_) => SettingsScreen( initialRunId: runsRoute.runId,
client: _session.client, initialPipelineId: runsRoute.pipelineId,
initialEndpoint: _session.endpoint, initialStageKey: runsRoute.stageKey,
embedded: true, initialVisit: runsRoute.visit,
onOpenTemplates: _delegate.openTemplates, initialDecide: runsRoute.decide,
onOpenSchedules: _delegate.openSchedules, listRefreshToken: _runsRefresh,
notifications: _notifications, notifications: _notifications,
), attention: _attention,
}, onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
); onBack: (id) => _delegate.goTo(
id == null ? AppRoute.runs : AppRoute.runsForPipeline(id),
),
onPipelineFilterChanged: (id) => _delegate.goTo(
id == null ? AppRoute.runs : AppRoute.runsForPipeline(id),
),
onOpenPipeline: (id, version) =>
_delegate.goTo(AppRoute.pipeline(id, version: version)),
),
),
AppDestination.chat: (_) => ChatDestination(
session: _session,
server: widget.server,
initialSessionId: chatRoute.chatSessionId,
onSessionSelected: (id) => _delegate.goTo(AppRoute.chatSession(id)),
onBack: () => _delegate.goTo(AppRoute.chat),
),
// Search is the fifth tab; a result opens its destination.
AppDestination.search: (_) => SearchDestination(
session: _session,
server: widget.server,
onOpen: _openSearchResult,
embedded: true,
),
AppDestination.settings: (_) => SettingsScreen(
client: _session.client,
initialEndpoint: _session.endpoint,
embedded: true,
onOpenTemplates: _delegate.openTemplates,
onOpenSchedules: _delegate.openSchedules,
notifications: _notifications,
),
},
);
}
AppDestination _destinationOf(AppRouteKind kind) => switch (kind) { AppDestination _destinationOf(AppRouteKind kind) => switch (kind) {
AppRouteKind.pipelines => AppDestination.pipelines, AppRouteKind.pipelines => AppDestination.pipelines,
AppRouteKind.runs => AppDestination.runs, AppRouteKind.runs => AppDestination.runs,
AppRouteKind.chat => AppDestination.chat, AppRouteKind.chat => AppDestination.chat,
// Search is a transient page above the shell; it never becomes a tab. AppRouteKind.search => AppDestination.search,
AppRouteKind.search => AppDestination.pipelines,
AppRouteKind.settings => AppDestination.settings, AppRouteKind.settings => AppDestination.settings,
// Templates and Schedules are Settings sub-pages, not a fifth tab. // Templates and Schedules are Settings sub-pages, not a fifth tab.
AppRouteKind.templates => AppDestination.settings, AppRouteKind.templates => AppDestination.settings,
@@ -477,6 +493,7 @@ class _PipelinesAppState extends State<PipelinesApp>
AppDestination.pipelines => AppRoute.pipelines, AppDestination.pipelines => AppRoute.pipelines,
AppDestination.runs => AppRoute.runs, AppDestination.runs => AppRoute.runs,
AppDestination.chat => AppRoute.chat, AppDestination.chat => AppRoute.chat,
AppDestination.search => AppRoute.search,
AppDestination.settings => AppRoute.settings, AppDestination.settings => AppRoute.settings,
}; };
@@ -22,12 +22,16 @@ class SearchDestination extends StatefulWidget {
required this.session, required this.session,
required this.server, required this.server,
required this.onOpen, required this.onOpen,
this.embedded = false,
}); });
final AppSession session; final AppSession session;
final ServerEndpoint server; final ServerEndpoint server;
final ValueChanged<JsonMap> onOpen; final ValueChanged<JsonMap> onOpen;
/// True as the shell's Search tab: no page chrome of its own.
final bool embedded;
@override @override
State<SearchDestination> createState() => _SearchDestinationState(); State<SearchDestination> createState() => _SearchDestinationState();
} }
@@ -75,6 +79,15 @@ class _SearchDestinationState extends State<SearchDestination> {
builder: (context, _) { builder: (context, _) {
final cupertino = usesCupertinoHost(context); final cupertino = usesCupertinoHost(context);
if (!widget.session.everConnected || !_entered) { if (!widget.session.everConnected || !_entered) {
if (widget.embedded) {
return _entered
? ConnectionGate(
session: widget.session,
server: widget.server,
cupertino: cupertino,
)
: const SizedBox.shrink();
}
return _SearchPage( return _SearchPage(
cupertino: cupertino, cupertino: cupertino,
child: _entered child: _entered
@@ -90,6 +103,7 @@ class _SearchDestinationState extends State<SearchDestination> {
gateway: widget.session.gateway, gateway: widget.session.gateway,
onOpen: widget.onOpen, onOpen: widget.onOpen,
cupertino: cupertino, cupertino: cupertino,
embedded: widget.embedded,
); );
}, },
); );
@@ -16,6 +16,7 @@ Widget buildCupertinoRunDetail({
required BuildContext context, required BuildContext context,
required JsonMap run, required JsonMap run,
required Widget headerActions, required Widget headerActions,
bool inShellBar = false,
ValueChanged<num>? onRunOpened, ValueChanged<num>? onRunOpened,
OpenPipeline? onOpenPipeline, OpenPipeline? onOpenPipeline,
required bool detailLoading, required bool detailLoading,
@@ -45,37 +46,39 @@ Widget buildCupertinoRunDetail({
header: Column( header: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Padding( // Inside the app shell, Back and the more menu are in its bar.
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0), if (!inShellBar)
child: Wrap( Padding(
alignment: WrapAlignment.spaceBetween, padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
crossAxisAlignment: WrapCrossAlignment.center, child: Wrap(
spacing: 8, alignment: WrapAlignment.spaceBetween,
runSpacing: 4, crossAxisAlignment: WrapCrossAlignment.center,
children: [ spacing: 8,
CupertinoButton( runSpacing: 4,
padding: EdgeInsets.zero, children: [
onPressed: onBack, CupertinoButton(
child: Row( padding: EdgeInsets.zero,
mainAxisSize: MainAxisSize.min, onPressed: onBack,
children: [ child: Row(
const Icon(CupertinoIcons.back), mainAxisSize: MainAxisSize.min,
const SizedBox(width: 4), children: [
const Text('Back'), const Icon(CupertinoIcons.back),
], const SizedBox(width: 4),
const Text('Back'),
],
),
), ),
), if (copying) const CupertinoActivityIndicator(),
if (copying) const CupertinoActivityIndicator(), RunMoreMenu(
RunMoreMenu( run: run,
run: run, gateway: gateway,
gateway: gateway, onRunChanged: onRunChanged,
onRunChanged: onRunChanged, cupertino: true,
cupertino: true, onRunOpened: onRunOpened,
onRunOpened: onRunOpened, ),
), ],
], ),
), ),
),
Padding( Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0), padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Column( child: Column(
@@ -16,6 +16,7 @@ Widget buildMaterialRunDetail({
required BuildContext context, required BuildContext context,
required JsonMap run, required JsonMap run,
required Widget headerActions, required Widget headerActions,
bool inShellBar = false,
ValueChanged<num>? onRunOpened, ValueChanged<num>? onRunOpened,
OpenPipeline? onOpenPipeline, OpenPipeline? onOpenPipeline,
required bool detailLoading, required bool detailLoading,
@@ -45,35 +46,37 @@ Widget buildMaterialRunDetail({
header: Column( header: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Padding( // Inside the app shell, Back and the more menu are in its bar.
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), if (!inShellBar)
child: Row( Padding(
crossAxisAlignment: CrossAxisAlignment.start, padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
children: [ child: Row(
Expanded( crossAxisAlignment: CrossAxisAlignment.start,
child: Wrap( children: [
spacing: 8, Expanded(
runSpacing: 4, child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center, spacing: 8,
children: [ runSpacing: 4,
TextButton.icon( crossAxisAlignment: WrapCrossAlignment.center,
onPressed: onBack, children: [
icon: const Icon(Icons.arrow_back), TextButton.icon(
label: const Text('Back to list'), onPressed: onBack,
), icon: const Icon(Icons.arrow_back),
], label: const Text('Back to list'),
),
],
),
), ),
), RunMoreMenu(
RunMoreMenu( run: run,
run: run, gateway: gateway,
gateway: gateway, onRunChanged: onRunChanged,
onRunChanged: onRunChanged, cupertino: false,
cupertino: false, onRunOpened: onRunOpened,
onRunOpened: onRunOpened, ),
), ],
], ),
), ),
),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
child: Align( child: Align(
+30 -1
View File
@@ -5,7 +5,9 @@ import 'package:flutter/services.dart';
import '../../../core/api_gateway.dart'; import '../../../core/api_gateway.dart';
import '../../../core/transport/pipelines_client.dart'; import '../../../core/transport/pipelines_client.dart';
import '../../../ui/adaptive/host.dart'; import '../../../ui/adaptive/host.dart';
import '../../../shell/shell_bar.dart';
import 'run_detail_actions.dart'; import 'run_detail_actions.dart';
import 'run_more_menu.dart';
import 'run_pipeline_link.dart'; import 'run_pipeline_link.dart';
import 'run_detail_content.dart'; import 'run_detail_content.dart';
import 'run_detail_cupertino.dart'; import 'run_detail_cupertino.dart';
@@ -67,13 +69,15 @@ class _RunDetailViewState extends State<RunDetailView> {
onRunOpened: widget.onRunOpened, onRunOpened: widget.onRunOpened,
retry: false, retry: false,
); );
return cupertino final inShellBar = ShellBar.available(context);
final detail = cupertino
? buildCupertinoRunDetail( ? buildCupertinoRunDetail(
context: context, context: context,
run: run, run: run,
headerActions: headerActions, headerActions: headerActions,
onRunOpened: widget.onRunOpened, onRunOpened: widget.onRunOpened,
onOpenPipeline: widget.onOpenPipeline, onOpenPipeline: widget.onOpenPipeline,
inShellBar: inShellBar,
detailLoading: widget.controller.detailLoading, detailLoading: widget.controller.detailLoading,
error: widget.controller.error, error: widget.controller.error,
copying: _copying, copying: _copying,
@@ -92,6 +96,7 @@ class _RunDetailViewState extends State<RunDetailView> {
headerActions: headerActions, headerActions: headerActions,
onRunOpened: widget.onRunOpened, onRunOpened: widget.onRunOpened,
onOpenPipeline: widget.onOpenPipeline, onOpenPipeline: widget.onOpenPipeline,
inShellBar: inShellBar,
detailLoading: widget.controller.detailLoading, detailLoading: widget.controller.detailLoading,
error: widget.controller.error, error: widget.controller.error,
copying: _copying, copying: _copying,
@@ -104,6 +109,22 @@ class _RunDetailViewState extends State<RunDetailView> {
initialStageKey: widget.initialStageKey, initialStageKey: widget.initialStageKey,
initialVisit: widget.initialVisit, initialVisit: widget.initialVisit,
); );
// The app bar becomes the run's: Back to the list, the run and its
// more menu. Search and the tab name return when the run closes.
return ShellBar(
title: 'Run ${run['id']}',
onBack: widget.onBack,
actions: [
RunMoreMenu(
run: run,
gateway: widget.gateway,
onRunChanged: widget.controller.acceptRunDetail,
cupertino: cupertino,
onRunOpened: widget.onRunOpened,
),
],
child: detail,
);
}, },
); );
@@ -114,6 +135,14 @@ class _RunDetailViewState extends State<RunDetailView> {
: widget.controller.error ?? 'Run details unavailable.'; : widget.controller.error ?? 'Run details unavailable.';
// Back stays available while the detail is pending as well as after a // Back stays available while the detail is pending as well as after a
// failure, so a slow or refused request can never trap the destination. // failure, so a slow or refused request can never trap the destination.
return ShellBar(
title: 'Run',
onBack: widget.onBack,
child: _placeholderBody(cupertino, loading, message),
);
}
Widget _placeholderBody(bool cupertino, bool loading, String message) {
return Center( return Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
+22 -10
View File
@@ -19,6 +19,7 @@ class SearchScreen extends StatefulWidget {
required this.gateway, required this.gateway,
required this.onOpen, required this.onOpen,
this.cupertino, this.cupertino,
this.embedded = false,
}); });
final ApiGateway gateway; final ApiGateway gateway;
@@ -28,6 +29,9 @@ class SearchScreen extends StatefulWidget {
/// Cupertino controls and every other platform uses Material. /// Cupertino controls and every other platform uses Material.
final bool? cupertino; final bool? cupertino;
/// True as the Search tab: the shell's bar names it, so no page bar.
final bool embedded;
@override @override
State<SearchScreen> createState() => _SearchScreenState(); State<SearchScreen> createState() => _SearchScreenState();
} }
@@ -112,17 +116,21 @@ class _SearchScreenState extends State<SearchScreen> {
return cupertino ? _cupertinoScreen() : _materialScreen(); return cupertino ? _cupertinoScreen() : _materialScreen();
} }
Widget _materialScreen() => Scaffold( Widget _materialScreen() {
appBar: AppBar(title: const Text('Search')), final body = SafeArea(
body: SafeArea(
child: MaterialSearchBody( child: MaterialSearchBody(
controller: _controller, controller: _controller,
query: _controller.parsed.query, query: _controller.parsed.query,
onOpen: widget.onOpen, onOpen: widget.onOpen,
header: _materialHeader(), header: _materialHeader(),
), ),
), );
); if (widget.embedded) return body;
return Scaffold(
appBar: AppBar(title: const Text('Search')),
body: body,
);
}
Widget _materialHeader() => Padding( Widget _materialHeader() => Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8), padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
@@ -175,17 +183,21 @@ class _SearchScreenState extends State<SearchScreen> {
), ),
); );
Widget _cupertinoScreen() => CupertinoPageScaffold( Widget _cupertinoScreen() {
navigationBar: const CupertinoNavigationBar(middle: Text('Search')), final body = SafeArea(
child: SafeArea(
child: CupertinoSearchBody( child: CupertinoSearchBody(
controller: _controller, controller: _controller,
query: _controller.parsed.query, query: _controller.parsed.query,
onOpen: widget.onOpen, onOpen: widget.onOpen,
header: _cupertinoHeader(context), header: _cupertinoHeader(context),
), ),
), );
); if (widget.embedded) return body;
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(middle: Text('Search')),
child: body,
);
}
Widget _cupertinoHeader(BuildContext context) => Padding( Widget _cupertinoHeader(BuildContext context) => Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8), padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
+140 -101
View File
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'attention_badge.dart'; import 'attention_badge.dart';
import 'destination.dart'; import 'destination.dart';
import 'shell_bar.dart';
class AdaptiveShell extends StatefulWidget { class AdaptiveShell extends StatefulWidget {
const AdaptiveShell({ const AdaptiveShell({
@@ -38,6 +39,13 @@ class AdaptiveShell extends StatefulWidget {
class _AdaptiveShellState extends State<AdaptiveShell> { class _AdaptiveShellState extends State<AdaptiveShell> {
late AppDestination _selected; late AppDestination _selected;
final Set<AppDestination> _visited = {}; final Set<AppDestination> _visited = {};
final ShellBarRegistry _bar = ShellBarRegistry();
@override
void dispose() {
_bar.dispose();
super.dispose();
}
@override @override
void initState() { void initState() {
@@ -90,114 +98,145 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
final item = destinationDetails(destination); final item = destinationDetails(destination);
return KeyedSubtree( return KeyedSubtree(
key: ValueKey(destination), key: ValueKey(destination),
child: _visited.contains(destination) child: ShellBarScope(
? widget.destinationBodies[destination]?.call(context) ?? registry: _bar,
Center(child: Text('${item.label} — Not implemented')) destination: destination,
: const SizedBox.shrink(), child: _visited.contains(destination)
? widget.destinationBodies[destination]?.call(context) ??
Center(child: Text('${item.label} — Not implemented'))
: const SizedBox.shrink(),
),
); );
}).toList(); }).toList();
return LayoutBuilder( return ListenableBuilder(
builder: (context, constraints) { listenable: _bar,
final wide = constraints.maxWidth >= 600; builder: (context, _) => LayoutBuilder(
if (widget.cupertino) { builder: (context, constraints) {
return CupertinoPageScaffold( final wide = constraints.maxWidth >= 600;
navigationBar: CupertinoNavigationBar( if (widget.cupertino) {
middle: Text(details.label), final spec = _bar.specFor(_selected);
trailing: widget.onSearch == null return CupertinoPageScaffold(
? null navigationBar: CupertinoNavigationBar(
: CupertinoButton( // The open screen's own bar: its Back, title and actions.
key: const ValueKey('shell.search'), leading: spec?.onBack == null
padding: EdgeInsets.zero, ? null
onPressed: widget.onSearch, : CupertinoNavigationBarBackButton(
child: const Icon( key: const ValueKey('shell.back'),
CupertinoIcons.search, onPressed: spec!.onBack,
semanticLabel: 'Search',
), ),
), automaticallyImplyLeading: false,
), middle: Text(spec?.title ?? details.label),
child: SafeArea( trailing: spec != null && spec.actions.isNotEmpty
child: wide ? Row(
// The web keeps a destination rail on a wide window. A native mainAxisSize: MainAxisSize.min,
// Cupertino sidebar list is the same idea with the host's own children: spec.actions,
// controls; the tab bar stays the narrow-window navigation. )
? Row( : widget.onSearch == null
children: [ ? null
_CupertinoSidebar( : CupertinoButton(
selected: _selected, key: const ValueKey('shell.search'),
onSelected: _select, padding: EdgeInsets.zero,
attentionCount: widget.attentionCount, onPressed: widget.onSearch,
child: const Icon(
CupertinoIcons.search,
semanticLabel: 'Search',
), ),
Expanded(child: _destinationStack(contents, index)), ),
], ),
) child: SafeArea(
: Column( child: wide
children: [ // The web keeps a destination rail on a wide window. A native
Expanded(child: _destinationStack(contents, index)), // Cupertino sidebar list is the same idea with the host's own
CupertinoTabBar( // controls; the tab bar stays the narrow-window navigation.
currentIndex: index, ? Row(
onTap: (value) => children: [
_select(AppDestination.values[value]), _CupertinoSidebar(
items: _items((destination) { selected: _selected,
final item = destinationDetails(destination); onSelected: _select,
return BottomNavigationBarItem( attentionCount: widget.attentionCount,
icon: _icon(destination, item.cupertinoIcon), ),
label: item.label, Expanded(child: _destinationStack(contents, index)),
); ],
}), )
), : Column(
], children: [
Expanded(child: _destinationStack(contents, index)),
CupertinoTabBar(
currentIndex: index,
onTap: (value) =>
_select(AppDestination.values[value]),
items: _items((destination) {
final item = destinationDetails(destination);
return BottomNavigationBarItem(
icon: _icon(destination, item.cupertinoIcon),
label: item.label,
);
}),
),
],
),
),
);
}
final spec = _bar.specFor(_selected);
return Scaffold(
appBar: AppBar(
// The open screen's own bar: its Back, title and actions.
automaticallyImplyLeading: false,
leading: spec?.onBack == null
? null
: BackButton(
key: const ValueKey('shell.back'),
onPressed: spec!.onBack,
), ),
title: Text(spec?.title ?? details.label),
actions: [
...?spec?.actions,
if (widget.onSearch != null && (spec?.actions.isEmpty ?? true))
IconButton(
key: const ValueKey('shell.search'),
onPressed: widget.onSearch,
tooltip: 'Search',
icon: const Icon(Icons.search),
),
],
), ),
body: Row(
children: [
if (wide)
NavigationRail(
selectedIndex: index,
onDestinationSelected: (value) =>
_select(AppDestination.values[value]),
labelType: NavigationRailLabelType.all,
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationRailDestination(
icon: _icon(destination, item.icon),
label: Text(item.label),
);
}),
),
Expanded(child: _destinationStack(contents, index)),
],
),
bottomNavigationBar: wide
? null
: NavigationBar(
selectedIndex: index,
onDestinationSelected: (value) =>
_select(AppDestination.values[value]),
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationDestination(
icon: _icon(destination, item.icon),
label: item.label,
);
}),
),
); );
} },
return Scaffold( ),
appBar: AppBar(
title: Text(details.label),
actions: [
if (widget.onSearch != null)
IconButton(
key: const ValueKey('shell.search'),
onPressed: widget.onSearch,
tooltip: 'Search',
icon: const Icon(Icons.search),
),
],
),
body: Row(
children: [
if (wide)
NavigationRail(
selectedIndex: index,
onDestinationSelected: (value) =>
_select(AppDestination.values[value]),
labelType: NavigationRailLabelType.all,
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationRailDestination(
icon: _icon(destination, item.icon),
label: Text(item.label),
);
}),
),
Expanded(child: _destinationStack(contents, index)),
],
),
bottomNavigationBar: wide
? null
: NavigationBar(
selectedIndex: index,
onDestinationSelected: (value) =>
_select(AppDestination.values[value]),
destinations: _items((destination) {
final item = destinationDetails(destination);
return NavigationDestination(
icon: _icon(destination, item.icon),
label: item.label,
);
}),
),
);
},
); );
} }
+6 -1
View File
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
enum AppDestination { pipelines, runs, chat, settings } enum AppDestination { pipelines, runs, chat, search, settings }
({String label, IconData icon, IconData cupertinoIcon}) destinationDetails( ({String label, IconData icon, IconData cupertinoIcon}) destinationDetails(
AppDestination value, AppDestination value,
@@ -21,6 +21,11 @@ enum AppDestination { pipelines, runs, chat, settings }
icon: Icons.chat_bubble_outline, icon: Icons.chat_bubble_outline,
cupertinoIcon: CupertinoIcons.chat_bubble_2, cupertinoIcon: CupertinoIcons.chat_bubble_2,
), ),
AppDestination.search => (
label: 'Search',
icon: Icons.search,
cupertinoIcon: CupertinoIcons.search,
),
AppDestination.settings => ( AppDestination.settings => (
label: 'Settings', label: 'Settings',
icon: Icons.settings_outlined, icon: Icons.settings_outlined,
+129
View File
@@ -0,0 +1,129 @@
import 'package:flutter/widgets.dart';
import 'destination.dart';
/// What the open screen of a tab puts in the app bar: its title, a Back
/// control and its actions. Absent, the bar shows the tab's own name.
class ShellBarSpec {
const ShellBarSpec({this.title, this.onBack, this.actions = const []});
final String? title;
final VoidCallback? onBack;
final List<Widget> actions;
}
/// The bar contents each tab's open screen has published.
class ShellBarRegistry extends ChangeNotifier {
final Map<AppDestination, (Object, ShellBarSpec)> _specs = {};
bool _disposed = false;
@override
void dispose() {
_disposed = true;
super.dispose();
}
ShellBarSpec? specFor(AppDestination destination) => _specs[destination]?.$2;
void _set(AppDestination destination, Object owner, ShellBarSpec spec) {
// A screen's update can land after the shell itself has gone.
if (_disposed) return;
_specs[destination] = (owner, spec);
notifyListeners();
}
void _clear(AppDestination destination, Object owner) {
if (_disposed) return;
if (_specs[destination]?.$1 != owner) return;
_specs.remove(destination);
notifyListeners();
}
}
/// Places one tab's content under the shell's bar registry.
class ShellBarScope extends InheritedWidget {
const ShellBarScope({
super.key,
required this.registry,
required this.destination,
required super.child,
});
final ShellBarRegistry registry;
final AppDestination destination;
static ShellBarScope? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ShellBarScope>();
@override
bool updateShouldNotify(ShellBarScope oldWidget) =>
registry != oldWidget.registry || destination != oldWidget.destination;
}
/// Puts [title], [onBack] and [actions] in the app bar while [child] is shown.
/// Outside a shell (a screen mounted on its own) it does nothing, so the
/// screen keeps its own controls.
class ShellBar extends StatefulWidget {
const ShellBar({
super.key,
this.title,
this.onBack,
this.actions = const [],
required this.child,
});
final String? title;
final VoidCallback? onBack;
final List<Widget> actions;
final Widget child;
/// Whether a shell bar will show these controls for the subtree at
/// [context].
static bool available(BuildContext context) =>
ShellBarScope.maybeOf(context) != null;
@override
State<ShellBar> createState() => _ShellBarState();
}
class _ShellBarState extends State<ShellBar> {
final Object _owner = Object();
ShellBarScope? _scope;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_scope = ShellBarScope.maybeOf(context);
}
void _publish() {
final scope = _scope;
if (scope == null) return;
final spec = ShellBarSpec(
title: widget.title,
onBack: widget.onBack,
actions: widget.actions,
);
// The bar is above this screen; update it after this frame's build.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) scope.registry._set(scope.destination, _owner, spec);
});
}
@override
void dispose() {
final scope = _scope;
if (scope != null) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => scope.registry._clear(scope.destination, _owner),
);
}
super.dispose();
}
@override
Widget build(BuildContext context) {
_publish();
return widget.child;
}
}
+8 -5
View File
@@ -159,11 +159,11 @@ void main() {
await replyDetail(tester, channel, 1); await replyDetail(tester, channel, 1);
expect(find.text('Run 1'), findsWidgets); expect(find.text('Run 1'), findsWidgets);
expect(find.text('Back to list'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
expect(provider.value.uri.path, '/runs/1'); expect(provider.value.uri.path, '/runs/1');
expect(find.text('Pipelines — Not implemented'), findsNothing); expect(find.text('Pipelines — Not implemented'), findsNothing);
await tester.tap(find.text('Back to list')); await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump(); await tester.pump();
expect(provider.value.uri.path, '/runs'); expect(provider.value.uri.path, '/runs');
expect(find.text('Deep-linked run'), findsWidgets); expect(find.text('Deep-linked run'), findsWidgets);
@@ -211,15 +211,17 @@ void main() {
await tester.pump(); await tester.pump();
expect(provider.value.uri.path, '/runs/2'); expect(provider.value.uri.path, '/runs/2');
await replyDetail(tester, channel, 2); await replyDetail(tester, channel, 2);
expect(find.text('Back to list'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
// The engine's browser Back arrives as new route information. // The engine's browser Back arrives as new route information.
await provider.didPushRouteInformation( await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/runs')), RouteInformation(uri: Uri.parse('/runs')),
); );
await tester.pump(); await tester.pump();
// The bar returns to the tab's own after the closed run hands it back.
await tester.pump();
expect(find.text('Beta run'), findsWidgets); expect(find.text('Beta run'), findsWidgets);
expect(find.text('Back to list'), findsNothing); expect(find.byKey(const ValueKey('shell.back')), findsNothing);
// Forward re-opens the same run. // Forward re-opens the same run.
await provider.didPushRouteInformation( await provider.didPushRouteInformation(
@@ -227,7 +229,8 @@ void main() {
); );
await tester.pump(); await tester.pump();
await replyDetail(tester, channel, 2); await replyDetail(tester, channel, 2);
expect(find.text('Back to list'), findsOneWidget); await tester.pump();
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
}); });
testWidgets('a malformed boot path is corrected to /pipelines', ( testWidgets('a malformed boot path is corrected to /pipelines', (
+32 -34
View File
@@ -1,7 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_route.dart'; import 'package:pipelines_app/application/app_route.dart';
import 'package:pipelines_app/application/app_router.dart'; import 'package:pipelines_app/application/app_router.dart';
@@ -85,13 +85,24 @@ Future<void> replyRun7List(WidgetTester tester, FakeChannel channel) => reply(
}, },
); );
/// Taps a tab by its label: the bottom bar or, on a wide window, the rail.
Future<void> tapTab(WidgetTester tester, String label) async {
final bar = find.byWidgetPredicate(
(widget) =>
widget is NavigationBar ||
widget is NavigationRail ||
widget is CupertinoTabBar,
);
await tester.tap(find.descendant(of: bar, matching: find.text(label)));
}
/// Opens Search, sends `report` and answers with the artifact hit for run 7. /// Opens Search, sends `report` and answers with the artifact hit for run 7.
Future<void> searchArtifactHit( Future<void> searchArtifactHit(
WidgetTester tester, WidgetTester tester,
FakeChannel channel, { FakeChannel channel, {
int index = 0, int index = 0,
}) async { }) async {
await tester.tap(find.byKey(const ValueKey('shell.search'))); await tapTab(tester, 'Search');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 600)); await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
@@ -255,7 +266,7 @@ Future<void> pumpApp(
void main() { void main() {
testWidgets( testWidgets(
'the shell action opens focused Search and Close keeps the open run', 'the Search tab opens focused and the Runs tab keeps the open run',
(tester) async { (tester) async {
tester.view.physicalSize = const Size(390, 844); tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
@@ -284,10 +295,10 @@ void main() {
); );
await replyRunList(tester, channel); await replyRunList(tester, channel);
await replyRunDetail(tester, channel, 2); await replyRunDetail(tester, channel, 2);
expect(find.text('Back to list'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
// The shell's existing action opens Search without adding a fifth tab. // Search is the fifth tab.
await tester.tap(find.byKey(const ValueKey('shell.search'))); await tapTab(tester, 'Search');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 600)); await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
@@ -302,35 +313,22 @@ void main() {
), ),
); );
expect(editable.focusNode.hasFocus, isTrue); expect(editable.focusNode.hasFocus, isTrue);
expect(find.byType(CloseButton), findsOneWidget);
// Closing is the native dialog action, not a second router or modal. // The Runs tab returns to the run that was open there.
await tester.tap(find.byType(CloseButton)); await tapTab(tester, 'Runs');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 400)); await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400)); await tester.pump(const Duration(milliseconds: 400));
expect(provider.value.uri.path, '/runs/2'); expect(provider.value.uri.path, '/runs/2');
expect(find.byType(SearchScreen), findsNothing); expect(find.byType(SearchScreen), findsNothing);
expect(find.text('Back to list'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
expect(find.text('Run 2'), findsWidgets); expect(find.text('Run 2'), findsWidgets);
// The shell was never remounted, so the open run was not re-read. // The shell was never remounted, so the open run was not re-read.
expect(requestsOf(channel, 'get_run'), hasLength(1)); expect(requestsOf(channel, 'get_run'), hasLength(1));
expect(requestsOf(channel, 'list_runs'), hasLength(1)); expect(requestsOf(channel, 'list_runs'), hasLength(1));
expect(sockets, 1); expect(sockets, 1);
// Escape is the browser panel's close shortcut on this page too.
await tester.tap(find.byKey(const ValueKey('shell.search')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100));
expect(provider.value.uri.path, '/search');
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(provider.value.uri.path, '/runs/2');
expect(find.text('Back to list'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink()); await tester.pumpWidget(const SizedBox.shrink());
await tester.pump(); await tester.pump();
}, },
@@ -367,7 +365,7 @@ void main() {
await replyRunList(tester, channel); await replyRunList(tester, channel);
await replyRunDetail(tester, channel, 2); await replyRunDetail(tester, channel, 2);
await tester.tap(find.byKey(const ValueKey('shell.search'))); await tapTab(tester, 'Search');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 600)); await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
@@ -409,7 +407,7 @@ void main() {
expect(provider.value.uri.path, '/runs/7'); expect(provider.value.uri.path, '/runs/7');
await replyRunDetail(tester, channel, 7, index: 1); await replyRunDetail(tester, channel, 7, index: 1);
expect(find.byType(SearchScreen), findsNothing); expect(find.byType(SearchScreen), findsNothing);
expect(find.text('Back to list'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
expect(find.text('Run 7'), findsWidgets); expect(find.text('Run 7'), findsWidgets);
// One app socket carried the search and the run reads. // One app socket carried the search and the run reads.
expect(sockets, 1); expect(sockets, 1);
@@ -450,7 +448,7 @@ void main() {
required int index, required int index,
required JsonMap hit, required JsonMap hit,
}) async { }) async {
await tester.tap(find.byKey(const ValueKey('shell.search'))); await tapTab(tester, 'Search');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 600)); await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
@@ -568,7 +566,7 @@ void main() {
); );
await replyRunList(tester, channel); await replyRunList(tester, channel);
await tester.tap(find.byKey(const ValueKey('shell.search'))); await tapTab(tester, 'Search');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 600)); await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
@@ -651,8 +649,8 @@ void main() {
// leaves from the loading placeholder instead. // leaves from the loading placeholder instead.
await openArtifactHit(tester, channel); await openArtifactHit(tester, channel);
expect(provider.value.uri.path, '/runs/7'); expect(provider.value.uri.path, '/runs/7');
expect(find.text('Back to list'), findsOneWidget); expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
await tester.tap(find.text('Back to list')); await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(provider.value.uri.path, '/runs'); expect(provider.value.uri.path, '/runs');
@@ -711,7 +709,7 @@ void main() {
await tester.tap(find.byKey(const Key('run-visit-back'))); await tester.tap(find.byKey(const Key('run-visit-back')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.text('Back to list')); await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(provider.value.uri.path, '/runs'); expect(provider.value.uri.path, '/runs');
@@ -732,7 +730,7 @@ void main() {
await tester.pump(); await tester.pump();
}); });
testWidgets('Cupertino uses its native bar action and Back', (tester) async { testWidgets('Cupertino Search is a native tab', (tester) async {
tester.view.physicalSize = const Size(390, 844); tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetPhysicalSize);
@@ -763,7 +761,7 @@ void main() {
await replyRunList(tester, channel); await replyRunList(tester, channel);
expect(find.text('Preserved run'), findsWidgets); expect(find.text('Preserved run'), findsWidgets);
await tester.tap(find.byKey(const ValueKey('shell.search'))); await tapTab(tester, 'Search');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 600)); await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
@@ -779,7 +777,7 @@ void main() {
); );
expect(cupertinoField.focusNode.hasFocus, isTrue); expect(cupertinoField.focusNode.hasFocus, isTrue);
await tester.tap(find.text('Cancel')); await tapTab(tester, 'Runs');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 400)); await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400)); await tester.pump(const Duration(milliseconds: 400));
@@ -844,8 +842,8 @@ void main() {
router.openSearch(); router.openSearch();
expect(router.route, AppRoute.search); expect(router.route, AppRoute.search);
expect(router.searchOpen, isTrue); expect(router.searchOpen, isTrue);
// Search is a page above the shell; the open run stays under it. // Without a page builder Search is the shell's own tab.
expect(router.shellRoute, AppRoute.run(3)); expect(router.shellRoute, AppRoute.search);
expect(await router.popRoute(), isTrue); expect(await router.popRoute(), isTrue);
expect(router.route, AppRoute.run(3)); expect(router.route, AppRoute.run(3));
+63
View File
@@ -0,0 +1,63 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/shell_bar.dart';
Widget _app({required bool cupertino, required bool open, VoidCallback? back}) {
final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => open
? ShellBar(
title: 'Run 7',
onBack: back,
actions: const [Icon(Icons.more_vert, key: Key('run-more'))],
child: const Text('detail'),
)
: const Text('list'),
},
);
return cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell);
}
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'cupertino' : 'material';
testWidgets('$host: an open screen takes over the bar and gives it back', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
var backs = 0;
await tester.pumpWidget(
_app(cupertino: cupertino, open: true, back: () => backs++),
);
await tester.pump();
expect(find.text('Run 7'), findsOneWidget);
expect(find.byKey(const Key('run-more')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back')));
expect(backs, 1);
await tester.pumpWidget(_app(cupertino: cupertino, open: false));
await tester.pump();
expect(find.text('Run 7'), findsNothing);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
expect(find.byKey(const Key('run-more')), findsNothing);
});
testWidgets('$host: Search is the fifth tab', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(_app(cupertino: cupertino, open: false));
expect(AppDestination.values, hasLength(5));
expect(find.text('Search'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
});
}
}