Make Settings a top-level navigation destination

Show Back only when Settings is reached through a pushed route, and remove duplicate Settings controls where the shell already provides navigation. Update focused widget coverage and document the destination behavior.
This commit is contained in:
2026-11-12 10:39:33 +00:00
parent 24618964ce
commit 77a88d09d3
12 changed files with 353 additions and 101 deletions
+6 -4
View File
@@ -90,8 +90,8 @@ void main() {
expect(find.text('runs body'), findsOneWidget);
});
testWidgets('Settings opens from the rail foot as a page and no tab is '
'selected meanwhile', (tester) async {
testWidgets('Settings opens from the rail foot as a destination with no '
'Back and no tab is selected meanwhile', (tester) async {
final semantics = tester.ensureSemantics();
await pumpShell(tester, width: 1000);
@@ -106,8 +106,10 @@ void main() {
.isSelected,
Tristate.isTrue,
);
// The page's own Back returns to Pipelines, the tab it belongs to.
await tester.tap(find.byKey(const ValueKey('shell.back')));
// Opened from its rail item, Settings is not a page: no Back.
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
// The Pipelines item leaves it for the Pipelines tab.
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
await tester.pumpAndSettle();
expect(tester.widget<NavigationRail>(rail()).selectedIndex, 0);
semantics.dispose();
+90
View File
@@ -0,0 +1,90 @@
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';
/// Settings' Back: a destination reached from a shell control has none; a page
/// pushed by a route (a first load or a route change, such as a deep link or
/// the Pipelines gear) has one that returns to Pipelines.
void main() {
AdaptiveShell shellAt(AppDestination destination) => AdaptiveShell(
destination: destination,
destinationBodies: {
for (final value in AppDestination.values)
value: (_) => Text('${value.name} body'),
},
);
Future<void> pumpAt(
WidgetTester tester,
AppDestination destination, {
double width = 1000,
}) async {
tester.view.physicalSize = Size(width, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(MaterialApp(home: shellAt(destination)));
await tester.pumpAndSettle();
}
testWidgets('Settings selected from a rail item has no Back', (tester) async {
await pumpAt(tester, AppDestination.pipelines);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
expect(find.text('settings body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
});
testWidgets('Settings selected from a phone bar item has no Back', (
tester,
) async {
await pumpAt(tester, AppDestination.pipelines, width: 390);
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
expect(find.text('settings body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
});
testWidgets('Settings pushed by a route change has Back, which returns to '
'Pipelines', (tester) async {
await pumpAt(tester, AppDestination.pipelines);
// The route moves to Settings (as a gear or a deep link does).
await tester.pumpWidget(
MaterialApp(home: shellAt(AppDestination.settings)),
);
await tester.pumpAndSettle();
expect(find.text('settings body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pumpAndSettle();
expect(find.text('pipelines body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
});
testWidgets('a first load on Settings (a deep link) has Back', (
tester,
) async {
await pumpAt(tester, AppDestination.settings);
expect(find.text('settings body'), findsOneWidget);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
});
testWidgets('a nav selection after a pushed Settings clears its Back', (
tester,
) async {
await pumpAt(tester, AppDestination.settings);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
await tester.pumpAndSettle();
expect(find.text('chat body'), findsOneWidget);
// Settings opened again from its rail item is a destination, not a page.
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
});
}