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:
@@ -56,8 +56,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
_searchReturn = initial.kind == AppRouteKind.search
|
||||
? AppRoute.pipelines
|
||||
: initial,
|
||||
_templatesReturn = initial.kind == AppRouteKind.templates
|
||||
|| initial.kind == AppRouteKind.schedules
|
||||
_templatesReturn =
|
||||
initial.kind == AppRouteKind.templates ||
|
||||
initial.kind == AppRouteKind.schedules
|
||||
? AppRoute.settings
|
||||
: initial;
|
||||
|
||||
@@ -111,7 +112,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
/// The route the shell renders underneath the transient Search, Templates
|
||||
/// and Schedules pages. Those pages keep the shell mounted, so the route the
|
||||
/// operator last opened there is still the shell's own destination.
|
||||
AppRoute get shellRoute => searchOpen
|
||||
AppRoute get shellRoute => searchOpen && searchBuilder != null
|
||||
? _searchReturn
|
||||
: templatesOpen || schedulesOpen
|
||||
? _templatesReturn
|
||||
@@ -256,7 +257,8 @@ RouteInformation initialRouteInformation() {
|
||||
if (!kIsWeb) {
|
||||
// A cold start from a deep link carries the full link as the platform's
|
||||
// initial route; an ordinary launch opens the Pipelines list.
|
||||
final launched = WidgetsBinding.instance.platformDispatcher.defaultRouteName;
|
||||
final launched =
|
||||
WidgetsBinding.instance.platformDispatcher.defaultRouteName;
|
||||
return RouteInformation(
|
||||
uri: launched.isEmpty || launched == '/'
|
||||
? Uri(path: '/pipelines')
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../core/api_gateway.dart';
|
||||
@@ -149,12 +148,13 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
cupertino: _cupertino,
|
||||
onPopToRuns: () => _delegate.goTo(AppRoute.runs),
|
||||
onPopToChat: () => _delegate.goTo(AppRoute.chat),
|
||||
searchBuilder: _buildSearch,
|
||||
templatesBuilder: _buildTemplates,
|
||||
schedulesBuilder: _buildSchedules,
|
||||
builder: _buildShell,
|
||||
);
|
||||
_delegate.addListener(_routeChanged);
|
||||
_tabRoutes[_destinationOf(_delegate.shellRoute.kind)] =
|
||||
_delegate.shellRoute;
|
||||
_chatQuestionNotices = ChatQuestionNotices(
|
||||
gateway: _session.gateway,
|
||||
canNotify: () => _notifications.canNotify,
|
||||
@@ -264,19 +264,6 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
Widget build(BuildContext context) =>
|
||||
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
|
||||
/// hit navigates nowhere: the screen already presents it read-only rather than
|
||||
/// guessing a destination.
|
||||
@@ -336,7 +323,21 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
/// 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
|
||||
/// 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() {
|
||||
final shown = _delegate.shellRoute;
|
||||
_tabRoutes[_destinationOf(shown.kind)] = shown;
|
||||
final pending = _pendingRunSearch;
|
||||
if (!mounted || pending == null) return;
|
||||
final route = _delegate.shellRoute;
|
||||
@@ -397,76 +398,91 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
builder: (context, count, _) => _shellFor(route, count),
|
||||
);
|
||||
|
||||
Widget _shellFor(AppRoute route, int attentionCount) => AdaptiveShell(
|
||||
attentionCount: attentionCount,
|
||||
cupertino: _cupertino,
|
||||
destination: _destinationOf(route.kind),
|
||||
onDestinationSelected: (destination) =>
|
||||
_delegate.goTo(_routeOf(destination)),
|
||||
onSearch: _delegate.openSearch,
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) => PipelinesDestination(
|
||||
session: _session,
|
||||
server: widget.server,
|
||||
refreshToken: _pipelinesRefresh,
|
||||
onRunStarted: _runStarted,
|
||||
onViewPipelineRuns: (id) =>
|
||||
_delegate.goTo(AppRoute.runsForPipeline(id)),
|
||||
initialPipelineId: route.pipelineId,
|
||||
initialVersion: route.version,
|
||||
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(
|
||||
Widget _shellFor(AppRoute route, int attentionCount) {
|
||||
// Each tab is built from the route it last showed, so switching tabs keeps
|
||||
// an open run, pipeline or chat instead of resetting it.
|
||||
AppRoute tab(AppDestination destination) =>
|
||||
_destinationOf(route.kind) == destination
|
||||
? route
|
||||
: _tabRoutes[destination] ?? _routeOf(destination);
|
||||
final pipelinesRoute = tab(AppDestination.pipelines);
|
||||
final runsRoute = tab(AppDestination.runs);
|
||||
final chatRoute = tab(AppDestination.chat);
|
||||
return AdaptiveShell(
|
||||
attentionCount: attentionCount,
|
||||
cupertino: _cupertino,
|
||||
destination: _destinationOf(route.kind),
|
||||
onDestinationSelected: _selectDestination,
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) => PipelinesDestination(
|
||||
session: _session,
|
||||
server: widget.server,
|
||||
initialRunId: route.runId,
|
||||
initialPipelineId: route.pipelineId,
|
||||
initialStageKey: route.stageKey,
|
||||
initialVisit: route.visit,
|
||||
initialDecide: route.decide,
|
||||
listRefreshToken: _runsRefresh,
|
||||
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)),
|
||||
refreshToken: _pipelinesRefresh,
|
||||
onRunStarted: _runStarted,
|
||||
onViewPipelineRuns: (id) =>
|
||||
_delegate.goTo(AppRoute.runsForPipeline(id)),
|
||||
initialPipelineId: pipelinesRoute.pipelineId,
|
||||
initialVersion: pipelinesRoute.version,
|
||||
initialStageKey: pipelinesRoute.stageKey,
|
||||
),
|
||||
),
|
||||
AppDestination.chat: (_) => ChatDestination(
|
||||
session: _session,
|
||||
server: widget.server,
|
||||
initialSessionId: route.chatSessionId,
|
||||
onSessionSelected: (id) => _delegate.goTo(AppRoute.chatSession(id)),
|
||||
onBack: () => _delegate.goTo(AppRoute.chat),
|
||||
),
|
||||
AppDestination.settings: (_) => SettingsScreen(
|
||||
client: _session.client,
|
||||
initialEndpoint: _session.endpoint,
|
||||
embedded: true,
|
||||
onOpenTemplates: _delegate.openTemplates,
|
||||
onOpenSchedules: _delegate.openSchedules,
|
||||
notifications: _notifications,
|
||||
),
|
||||
},
|
||||
);
|
||||
// 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,
|
||||
server: widget.server,
|
||||
initialRunId: runsRoute.runId,
|
||||
initialPipelineId: runsRoute.pipelineId,
|
||||
initialStageKey: runsRoute.stageKey,
|
||||
initialVisit: runsRoute.visit,
|
||||
initialDecide: runsRoute.decide,
|
||||
listRefreshToken: _runsRefresh,
|
||||
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) {
|
||||
AppRouteKind.pipelines => AppDestination.pipelines,
|
||||
AppRouteKind.runs => AppDestination.runs,
|
||||
AppRouteKind.chat => AppDestination.chat,
|
||||
// Search is a transient page above the shell; it never becomes a tab.
|
||||
AppRouteKind.search => AppDestination.pipelines,
|
||||
AppRouteKind.search => AppDestination.search,
|
||||
AppRouteKind.settings => AppDestination.settings,
|
||||
// Templates and Schedules are Settings sub-pages, not a fifth tab.
|
||||
AppRouteKind.templates => AppDestination.settings,
|
||||
@@ -477,6 +493,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
AppDestination.pipelines => AppRoute.pipelines,
|
||||
AppDestination.runs => AppRoute.runs,
|
||||
AppDestination.chat => AppRoute.chat,
|
||||
AppDestination.search => AppRoute.search,
|
||||
AppDestination.settings => AppRoute.settings,
|
||||
};
|
||||
|
||||
|
||||
@@ -22,12 +22,16 @@ class SearchDestination extends StatefulWidget {
|
||||
required this.session,
|
||||
required this.server,
|
||||
required this.onOpen,
|
||||
this.embedded = false,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
final ServerEndpoint server;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
|
||||
/// True as the shell's Search tab: no page chrome of its own.
|
||||
final bool embedded;
|
||||
|
||||
@override
|
||||
State<SearchDestination> createState() => _SearchDestinationState();
|
||||
}
|
||||
@@ -75,6 +79,15 @@ class _SearchDestinationState extends State<SearchDestination> {
|
||||
builder: (context, _) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
if (!widget.session.everConnected || !_entered) {
|
||||
if (widget.embedded) {
|
||||
return _entered
|
||||
? ConnectionGate(
|
||||
session: widget.session,
|
||||
server: widget.server,
|
||||
cupertino: cupertino,
|
||||
)
|
||||
: const SizedBox.shrink();
|
||||
}
|
||||
return _SearchPage(
|
||||
cupertino: cupertino,
|
||||
child: _entered
|
||||
@@ -90,6 +103,7 @@ class _SearchDestinationState extends State<SearchDestination> {
|
||||
gateway: widget.session.gateway,
|
||||
onOpen: widget.onOpen,
|
||||
cupertino: cupertino,
|
||||
embedded: widget.embedded,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -16,6 +16,7 @@ Widget buildCupertinoRunDetail({
|
||||
required BuildContext context,
|
||||
required JsonMap run,
|
||||
required Widget headerActions,
|
||||
bool inShellBar = false,
|
||||
ValueChanged<num>? onRunOpened,
|
||||
OpenPipeline? onOpenPipeline,
|
||||
required bool detailLoading,
|
||||
@@ -45,37 +46,39 @@ Widget buildCupertinoRunDetail({
|
||||
header: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onBack,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(CupertinoIcons.back),
|
||||
const SizedBox(width: 4),
|
||||
const Text('Back'),
|
||||
],
|
||||
// Inside the app shell, Back and the more menu are in its bar.
|
||||
if (!inShellBar)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onBack,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(CupertinoIcons.back),
|
||||
const SizedBox(width: 4),
|
||||
const Text('Back'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (copying) const CupertinoActivityIndicator(),
|
||||
RunMoreMenu(
|
||||
run: run,
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
cupertino: true,
|
||||
onRunOpened: onRunOpened,
|
||||
),
|
||||
],
|
||||
if (copying) const CupertinoActivityIndicator(),
|
||||
RunMoreMenu(
|
||||
run: run,
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
cupertino: true,
|
||||
onRunOpened: onRunOpened,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Column(
|
||||
|
||||
@@ -16,6 +16,7 @@ Widget buildMaterialRunDetail({
|
||||
required BuildContext context,
|
||||
required JsonMap run,
|
||||
required Widget headerActions,
|
||||
bool inShellBar = false,
|
||||
ValueChanged<num>? onRunOpened,
|
||||
OpenPipeline? onOpenPipeline,
|
||||
required bool detailLoading,
|
||||
@@ -45,35 +46,37 @@ Widget buildMaterialRunDetail({
|
||||
header: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to list'),
|
||||
),
|
||||
],
|
||||
// Inside the app shell, Back and the more menu are in its bar.
|
||||
if (!inShellBar)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to list'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
RunMoreMenu(
|
||||
run: run,
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
cupertino: false,
|
||||
onRunOpened: onRunOpened,
|
||||
),
|
||||
],
|
||||
RunMoreMenu(
|
||||
run: run,
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
cupertino: false,
|
||||
onRunOpened: onRunOpened,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||
child: Align(
|
||||
|
||||
@@ -5,7 +5,9 @@ import 'package:flutter/services.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/transport/pipelines_client.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../../shell/shell_bar.dart';
|
||||
import 'run_detail_actions.dart';
|
||||
import 'run_more_menu.dart';
|
||||
import 'run_pipeline_link.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_cupertino.dart';
|
||||
@@ -67,13 +69,15 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
onRunOpened: widget.onRunOpened,
|
||||
retry: false,
|
||||
);
|
||||
return cupertino
|
||||
final inShellBar = ShellBar.available(context);
|
||||
final detail = cupertino
|
||||
? buildCupertinoRunDetail(
|
||||
context: context,
|
||||
run: run,
|
||||
headerActions: headerActions,
|
||||
onRunOpened: widget.onRunOpened,
|
||||
onOpenPipeline: widget.onOpenPipeline,
|
||||
inShellBar: inShellBar,
|
||||
detailLoading: widget.controller.detailLoading,
|
||||
error: widget.controller.error,
|
||||
copying: _copying,
|
||||
@@ -92,6 +96,7 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
headerActions: headerActions,
|
||||
onRunOpened: widget.onRunOpened,
|
||||
onOpenPipeline: widget.onOpenPipeline,
|
||||
inShellBar: inShellBar,
|
||||
detailLoading: widget.controller.detailLoading,
|
||||
error: widget.controller.error,
|
||||
copying: _copying,
|
||||
@@ -104,6 +109,22 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
initialStageKey: widget.initialStageKey,
|
||||
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.';
|
||||
// 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.
|
||||
return ShellBar(
|
||||
title: 'Run',
|
||||
onBack: widget.onBack,
|
||||
child: _placeholderBody(cupertino, loading, message),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _placeholderBody(bool cupertino, bool loading, String message) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
@@ -19,6 +19,7 @@ class SearchScreen extends StatefulWidget {
|
||||
required this.gateway,
|
||||
required this.onOpen,
|
||||
this.cupertino,
|
||||
this.embedded = false,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -28,6 +29,9 @@ class SearchScreen extends StatefulWidget {
|
||||
/// Cupertino controls and every other platform uses Material.
|
||||
final bool? cupertino;
|
||||
|
||||
/// True as the Search tab: the shell's bar names it, so no page bar.
|
||||
final bool embedded;
|
||||
|
||||
@override
|
||||
State<SearchScreen> createState() => _SearchScreenState();
|
||||
}
|
||||
@@ -112,17 +116,21 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
return cupertino ? _cupertinoScreen() : _materialScreen();
|
||||
}
|
||||
|
||||
Widget _materialScreen() => Scaffold(
|
||||
appBar: AppBar(title: const Text('Search')),
|
||||
body: SafeArea(
|
||||
Widget _materialScreen() {
|
||||
final body = SafeArea(
|
||||
child: MaterialSearchBody(
|
||||
controller: _controller,
|
||||
query: _controller.parsed.query,
|
||||
onOpen: widget.onOpen,
|
||||
header: _materialHeader(),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
if (widget.embedded) return body;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Search')),
|
||||
body: body,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _materialHeader() => Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
|
||||
@@ -175,17 +183,21 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
),
|
||||
);
|
||||
|
||||
Widget _cupertinoScreen() => CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text('Search')),
|
||||
child: SafeArea(
|
||||
Widget _cupertinoScreen() {
|
||||
final body = SafeArea(
|
||||
child: CupertinoSearchBody(
|
||||
controller: _controller,
|
||||
query: _controller.parsed.query,
|
||||
onOpen: widget.onOpen,
|
||||
header: _cupertinoHeader(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
if (widget.embedded) return body;
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text('Search')),
|
||||
child: body,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoHeader(BuildContext context) => Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
|
||||
|
||||
+140
-101
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'attention_badge.dart';
|
||||
import 'destination.dart';
|
||||
import 'shell_bar.dart';
|
||||
|
||||
class AdaptiveShell extends StatefulWidget {
|
||||
const AdaptiveShell({
|
||||
@@ -38,6 +39,13 @@ class AdaptiveShell extends StatefulWidget {
|
||||
class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
late AppDestination _selected;
|
||||
final Set<AppDestination> _visited = {};
|
||||
final ShellBarRegistry _bar = ShellBarRegistry();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_bar.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -90,114 +98,145 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
final item = destinationDetails(destination);
|
||||
return KeyedSubtree(
|
||||
key: ValueKey(destination),
|
||||
child: _visited.contains(destination)
|
||||
? widget.destinationBodies[destination]?.call(context) ??
|
||||
Center(child: Text('${item.label} — Not implemented'))
|
||||
: const SizedBox.shrink(),
|
||||
child: ShellBarScope(
|
||||
registry: _bar,
|
||||
destination: destination,
|
||||
child: _visited.contains(destination)
|
||||
? widget.destinationBodies[destination]?.call(context) ??
|
||||
Center(child: Text('${item.label} — Not implemented'))
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= 600;
|
||||
if (widget.cupertino) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(details.label),
|
||||
trailing: widget.onSearch == null
|
||||
? null
|
||||
: CupertinoButton(
|
||||
key: const ValueKey('shell.search'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: widget.onSearch,
|
||||
child: const Icon(
|
||||
CupertinoIcons.search,
|
||||
semanticLabel: 'Search',
|
||||
return ListenableBuilder(
|
||||
listenable: _bar,
|
||||
builder: (context, _) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= 600;
|
||||
if (widget.cupertino) {
|
||||
final spec = _bar.specFor(_selected);
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
// The open screen's own bar: its Back, title and actions.
|
||||
leading: spec?.onBack == null
|
||||
? null
|
||||
: CupertinoNavigationBarBackButton(
|
||||
key: const ValueKey('shell.back'),
|
||||
onPressed: spec!.onBack,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: wide
|
||||
// The web keeps a destination rail on a wide window. A native
|
||||
// Cupertino sidebar list is the same idea with the host's own
|
||||
// controls; the tab bar stays the narrow-window navigation.
|
||||
? Row(
|
||||
children: [
|
||||
_CupertinoSidebar(
|
||||
selected: _selected,
|
||||
onSelected: _select,
|
||||
attentionCount: widget.attentionCount,
|
||||
automaticallyImplyLeading: false,
|
||||
middle: Text(spec?.title ?? details.label),
|
||||
trailing: spec != null && spec.actions.isNotEmpty
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: spec.actions,
|
||||
)
|
||||
: widget.onSearch == null
|
||||
? null
|
||||
: CupertinoButton(
|
||||
key: const ValueKey('shell.search'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: widget.onSearch,
|
||||
child: const Icon(
|
||||
CupertinoIcons.search,
|
||||
semanticLabel: 'Search',
|
||||
),
|
||||
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,
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: wide
|
||||
// The web keeps a destination rail on a wide window. A native
|
||||
// Cupertino sidebar list is the same idea with the host's own
|
||||
// controls; the tab bar stays the narrow-window navigation.
|
||||
? Row(
|
||||
children: [
|
||||
_CupertinoSidebar(
|
||||
selected: _selected,
|
||||
onSelected: _select,
|
||||
attentionCount: widget.attentionCount,
|
||||
),
|
||||
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,
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.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(
|
||||
AppDestination value,
|
||||
@@ -21,6 +21,11 @@ enum AppDestination { pipelines, runs, chat, settings }
|
||||
icon: Icons.chat_bubble_outline,
|
||||
cupertinoIcon: CupertinoIcons.chat_bubble_2,
|
||||
),
|
||||
AppDestination.search => (
|
||||
label: 'Search',
|
||||
icon: Icons.search,
|
||||
cupertinoIcon: CupertinoIcons.search,
|
||||
),
|
||||
AppDestination.settings => (
|
||||
label: 'Settings',
|
||||
icon: Icons.settings_outlined,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -159,11 +159,11 @@ void main() {
|
||||
await replyDetail(tester, channel, 1);
|
||||
|
||||
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(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();
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
expect(find.text('Deep-linked run'), findsWidgets);
|
||||
@@ -211,15 +211,17 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/runs/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.
|
||||
await provider.didPushRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('/runs')),
|
||||
);
|
||||
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('Back to list'), findsNothing);
|
||||
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
||||
|
||||
// Forward re-opens the same run.
|
||||
await provider.didPushRouteInformation(
|
||||
@@ -227,7 +229,8 @@ void main() {
|
||||
);
|
||||
await tester.pump();
|
||||
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', (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_route.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.
|
||||
Future<void> searchArtifactHit(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel, {
|
||||
int index = 0,
|
||||
}) async {
|
||||
await tester.tap(find.byKey(const ValueKey('shell.search')));
|
||||
await tapTab(tester, 'Search');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -255,7 +266,7 @@ Future<void> pumpApp(
|
||||
|
||||
void main() {
|
||||
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.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -284,10 +295,10 @@ void main() {
|
||||
);
|
||||
await replyRunList(tester, channel);
|
||||
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.
|
||||
await tester.tap(find.byKey(const ValueKey('shell.search')));
|
||||
// Search is the fifth tab.
|
||||
await tapTab(tester, 'Search');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -302,35 +313,22 @@ void main() {
|
||||
),
|
||||
);
|
||||
expect(editable.focusNode.hasFocus, isTrue);
|
||||
expect(find.byType(CloseButton), findsOneWidget);
|
||||
|
||||
// Closing is the native dialog action, not a second router or modal.
|
||||
await tester.tap(find.byType(CloseButton));
|
||||
// The Runs tab returns to the run that was open there.
|
||||
await tapTab(tester, 'Runs');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
|
||||
expect(provider.value.uri.path, '/runs/2');
|
||||
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);
|
||||
// The shell was never remounted, so the open run was not re-read.
|
||||
expect(requestsOf(channel, 'get_run'), hasLength(1));
|
||||
expect(requestsOf(channel, 'list_runs'), hasLength(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.pump();
|
||||
},
|
||||
@@ -367,7 +365,7 @@ void main() {
|
||||
await replyRunList(tester, channel);
|
||||
await replyRunDetail(tester, channel, 2);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('shell.search')));
|
||||
await tapTab(tester, 'Search');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -409,7 +407,7 @@ void main() {
|
||||
expect(provider.value.uri.path, '/runs/7');
|
||||
await replyRunDetail(tester, channel, 7, index: 1);
|
||||
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);
|
||||
// One app socket carried the search and the run reads.
|
||||
expect(sockets, 1);
|
||||
@@ -450,7 +448,7 @@ void main() {
|
||||
required int index,
|
||||
required JsonMap hit,
|
||||
}) async {
|
||||
await tester.tap(find.byKey(const ValueKey('shell.search')));
|
||||
await tapTab(tester, 'Search');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -568,7 +566,7 @@ void main() {
|
||||
);
|
||||
await replyRunList(tester, channel);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('shell.search')));
|
||||
await tapTab(tester, 'Search');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -651,8 +649,8 @@ void main() {
|
||||
// leaves from the loading placeholder instead.
|
||||
await openArtifactHit(tester, channel);
|
||||
expect(provider.value.uri.path, '/runs/7');
|
||||
expect(find.text('Back to list'), findsOneWidget);
|
||||
await tester.tap(find.text('Back to list'));
|
||||
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const ValueKey('shell.back')));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
@@ -711,7 +709,7 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('run-visit-back')));
|
||||
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();
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
@@ -732,7 +730,7 @@ void main() {
|
||||
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.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
@@ -763,7 +761,7 @@ void main() {
|
||||
await replyRunList(tester, channel);
|
||||
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(const Duration(milliseconds: 600));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -779,7 +777,7 @@ void main() {
|
||||
);
|
||||
expect(cupertinoField.focusNode.hasFocus, isTrue);
|
||||
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tapTab(tester, 'Runs');
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
@@ -844,8 +842,8 @@ void main() {
|
||||
router.openSearch();
|
||||
expect(router.route, AppRoute.search);
|
||||
expect(router.searchOpen, isTrue);
|
||||
// Search is a page above the shell; the open run stays under it.
|
||||
expect(router.shellRoute, AppRoute.run(3));
|
||||
// Without a page builder Search is the shell's own tab.
|
||||
expect(router.shellRoute, AppRoute.search);
|
||||
|
||||
expect(await router.popRoute(), isTrue);
|
||||
expect(router.route, AppRoute.run(3));
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user