Merge pull request #235 from cogwheel0/conversation-delta-ref-support
conversation-delta-ref-support
This commit is contained in:
@@ -69,6 +69,14 @@ class ConversationDeltaListener {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (ref is WidgetRef) {
|
||||||
|
_subscription = ref.listenManual(
|
||||||
|
conversationDeltaStreamProvider(_request),
|
||||||
|
handleNext,
|
||||||
|
fireImmediately: false,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (ref is ProviderContainer) {
|
if (ref is ProviderContainer) {
|
||||||
_subscription = ref.listen(
|
_subscription = ref.listen(
|
||||||
conversationDeltaStreamProvider(_request),
|
conversationDeltaStreamProvider(_request),
|
||||||
@@ -102,6 +110,9 @@ class ConversationDeltaListener {
|
|||||||
if (ref is Ref) {
|
if (ref is Ref) {
|
||||||
return ref.mounted;
|
return ref.mounted;
|
||||||
}
|
}
|
||||||
|
// For WidgetRef and ProviderContainer, rely on explicit disposal.
|
||||||
|
// Callers using WidgetRef must ensure dispose() is called when the
|
||||||
|
// widget unmounts.
|
||||||
return !_disposed;
|
return !_disposed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1878,12 +1878,16 @@ Future<void> _sendMessageInternal(
|
|||||||
// Adding a small delay to prevent rapid invalidations that could cause duplicates
|
// Adding a small delay to prevent rapid invalidations that could cause duplicates
|
||||||
Future.delayed(const Duration(milliseconds: 100), () {
|
Future.delayed(const Duration(milliseconds: 100), () {
|
||||||
try {
|
try {
|
||||||
// Guard against using ref after widget disposal
|
// Guard against using ref after provider disposal
|
||||||
if (ref.mounted == true) {
|
// Only Ref has .mounted; WidgetRef/ProviderContainer don't support
|
||||||
|
// this check, so we proceed and let the underlying read operations
|
||||||
|
// handle any disposal gracefully.
|
||||||
|
final isMounted = ref is Ref ? ref.mounted : true;
|
||||||
|
if (isMounted) {
|
||||||
refreshConversationsCache(ref);
|
refreshConversationsCache(ref);
|
||||||
}
|
}
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// If ref doesn't support mounted or is disposed, skip
|
// If ref is disposed or invalid, skip
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user