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:
@@ -25,16 +25,19 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
ref.read(chatProvider.notifier).connect(widget.sessionId);
|
||||
Future.microtask(() {
|
||||
ref.read(chatProvider.notifier).connect(widget.sessionId);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
ref.read(chatProvider.notifier).disconnect();
|
||||
final notifier = ref.read(chatProvider.notifier);
|
||||
_messageController.dispose();
|
||||
_scrollController.dispose();
|
||||
_typingThrottle?.cancel();
|
||||
super.dispose();
|
||||
Future.microtask(() => notifier.disconnect());
|
||||
}
|
||||
|
||||
void _scrollToBottom() {
|
||||
|
||||
Reference in New Issue
Block a user