Files
pipelines/app/test/shell/detail_page_close_test.dart
T
alan 19b1d1326a Close the phone chat page explicitly from its Back button
The chat page's Back had no handler and relied on the stock Back popping
the nearest route, while the system gesture went through the app's own
back handling. Back now pops the page's own route (or leaves the open
chat), the same path the gesture takes.
2026-11-12 19:20:33 +00:00

77 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/detail_page.dart';
/// A screen that opens one detail page whose content sits inside its own
/// inner navigator, as a chat pane can, with a Back that calls [onBack].
class _Host extends StatefulWidget {
const _Host({required this.page, required this.useClose});
final DetailPageHost page;
final bool useClose;
@override
State<_Host> createState() => _HostState();
}
class _HostState extends State<_Host> {
bool selected = true;
int closed = 0;
@override
Widget build(BuildContext context) {
widget.page.sync(
context,
selected: selected,
destination: AppDestination.chat,
onClosed: () => setState(() {
selected = false;
closed++;
}),
builder: (_) => Navigator(
pages: [
MaterialPage<void>(
child: Scaffold(
body: Center(
child: BackButton(
key: const Key('inner-back'),
onPressed: widget.useClose ? widget.page.close : null,
),
),
),
),
],
onDidRemovePage: (_) {},
),
);
return Scaffold(body: Text('list (closed $closed)'));
}
}
void main() {
testWidgets('close pops the page even from inside an inner navigator', (
tester,
) async {
final page = DetailPageHost();
await tester.pumpWidget(
MaterialApp(home: _Host(page: page, useClose: true)),
);
await tester.pumpAndSettle();
expect(page.open, isTrue);
expect(find.byKey(const Key('inner-back')), findsOneWidget);
await tester.tap(find.byKey(const Key('inner-back')));
await tester.pumpAndSettle();
expect(page.open, isFalse);
expect(find.byKey(const Key('inner-back')), findsNothing);
expect(find.text('list (closed 1)'), findsOneWidget);
});
testWidgets('close does nothing without an open page', (tester) async {
final page = DetailPageHost();
page.close();
expect(page.open, isFalse);
});
}