Fix chat page stuck: defer provider state changes past build phase

connect() and disconnect() were modifying provider state inside
initState/dispose, which Riverpod disallows during widget tree building.
Wrapped both in Future.microtask() to defer past the build phase.
Applied to both mitra_app and client_app.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-10 10:15:01 +08:00
parent bb0346a843
commit e601e19aab
2 changed files with 10 additions and 4 deletions

View File

@@ -24,16 +24,19 @@ class _MitraChatScreenState extends ConsumerState<MitraChatScreen> {
@override
void initState() {
super.initState();
ref.read(mitraChatProvider.notifier).connect(widget.sessionId);
Future.microtask(() {
ref.read(mitraChatProvider.notifier).connect(widget.sessionId);
});
}
@override
void dispose() {
ref.read(mitraChatProvider.notifier).disconnect();
final notifier = ref.read(mitraChatProvider.notifier);
_messageController.dispose();
_scrollController.dispose();
_typingThrottle?.cancel();
super.dispose();
Future.microtask(() => notifier.disconnect());
}
void _scrollToBottom() {