Hide the phone chat as soon as its Back is pressed
_back marked the open chat hidden without rebuilding and relied on the owner's route change to redraw. When the chat was shown while the app was already on /chat (a restored layout, the Chat tab re-selected) nothing changed, so the chat stayed on screen for seconds while the list behind it took the taps. Found on the device: closeChat logged route=null and the entrance never animated out. _back now rebuilds itself.
This commit is contained in:
@@ -333,17 +333,26 @@ class _ChatScreenState extends State<ChatScreen>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void _back() {
|
void _back() {
|
||||||
_workspaceVisible = false;
|
// Rebuild here rather than wait for the owner's route change: when the
|
||||||
_publishedWorkspaceSession = null;
|
// chat was shown without its own route (the Chat tab re-selected, a
|
||||||
|
// restored layout) the owner is already on /chat, nothing else rebuilds
|
||||||
|
// this screen, and the chat would stay on screen while the list behind
|
||||||
|
// it took the taps.
|
||||||
|
void hide() {
|
||||||
|
_workspaceVisible = false;
|
||||||
|
_publishedWorkspaceSession = null;
|
||||||
|
if (widget.onBack == null) _standaloneSelection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(hide);
|
||||||
|
} else {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
_runtime.startNotice = null;
|
_runtime.startNotice = null;
|
||||||
_composerFocus.cancel();
|
_composerFocus.cancel();
|
||||||
if (_workspace.paneCount == 0) widget.onWorkspaceEmpty?.call();
|
if (_workspace.paneCount == 0) widget.onWorkspaceEmpty?.call();
|
||||||
final back = widget.onBack;
|
widget.onBack?.call();
|
||||||
if (back != null) {
|
|
||||||
back();
|
|
||||||
} else {
|
|
||||||
setState(() => _standaloneSelection = null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// On a phone the open chat is a real page above the main screen.
|
/// On a phone the open chat is a real page above the main screen.
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/screen.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||||
|
|
||||||
|
import 'conversation/chat_thread_fixtures.dart';
|
||||||
|
|
||||||
|
class _Gateway extends FakeChatGateway {
|
||||||
|
@override
|
||||||
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||||
|
if (type == 'chat_sessions') {
|
||||||
|
return Future.value({
|
||||||
|
'chat_sessions': [
|
||||||
|
for (final id in ['a', 'b'])
|
||||||
|
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||||
|
return super.call(type, fields);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Finder _thread(String id) => find.byWidgetPredicate(
|
||||||
|
(widget) => widget is ChatThreadView && widget.sessionId == id,
|
||||||
|
);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('phone Back hides a restored chat at once when the owner is '
|
||||||
|
'already on the chat list route', (tester) async {
|
||||||
|
// A restored layout shows chat a while the app is already on /chat: Back
|
||||||
|
// asks the owner to go to /chat, which changes nothing, so the screen must
|
||||||
|
// hide the chat itself instead of waiting for an unrelated rebuild.
|
||||||
|
final layout = ChatWorkspaceController()..open('a');
|
||||||
|
SharedPreferences.setMockInitialValues({
|
||||||
|
chatWorkspacePreferenceKey: layout.snapshot()!.encode(),
|
||||||
|
});
|
||||||
|
tester.view.physicalSize = const Size(412, 915);
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.reset);
|
||||||
|
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||||
|
addTearDown(gateway.close);
|
||||||
|
var backs = 0;
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: ChatScreen(
|
||||||
|
gateway: gateway,
|
||||||
|
persistWorkspace: true,
|
||||||
|
onSessionSelected: (_) {},
|
||||||
|
onBack: () => backs++,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(_thread('a'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byType(BackButton).hitTestable());
|
||||||
|
// Only the screen's own frames: nothing else rebuilds it.
|
||||||
|
for (var i = 0; i < 30; i++) {
|
||||||
|
await tester.pump(const Duration(milliseconds: 16));
|
||||||
|
}
|
||||||
|
expect(backs, 1);
|
||||||
|
expect(_thread('a'), findsNothing);
|
||||||
|
expect(find.text('Chat a').hitTestable(), findsWidgets);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user