fix(navigation): Ensure context is mounted before navigation and improve error handling

This commit is contained in:
cogwheel0
2025-12-05 22:24:36 +05:30
parent a5c7bbe2f2
commit c9b888df79
2 changed files with 4 additions and 3 deletions

View File

@@ -370,7 +370,7 @@ class AppIntentCoordinator extends _$AppIntentCoordinator {
await Future<void>.delayed(const Duration(milliseconds: 50)); await Future<void>.delayed(const Duration(milliseconds: 50));
final context = NavigationService.navigatorKey.currentContext; final context = NavigationService.navigatorKey.currentContext;
if (context == null) { if (context == null || !context.mounted) {
throw StateError('Navigation context not available.'); throw StateError('Navigation context not available.');
} }
@@ -378,6 +378,7 @@ class AppIntentCoordinator extends _$AppIntentCoordinator {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
// Navigate to voice call page with new conversation flag // Navigate to voice call page with new conversation flag
if (!context.mounted) return;
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (_) => const VoiceCallPage(startNewConversation: true), builder: (_) => const VoiceCallPage(startNewConversation: true),

View File

@@ -1965,7 +1965,7 @@ class _ModernChatInputState extends ConsumerState<ModernChatInput>
height: IconSize.small + 1, height: IconSize.small + 1,
color: iconUrl.endsWith('.svg') ? iconColor : null, color: iconUrl.endsWith('.svg') ? iconColor : null,
colorBlendMode: BlendMode.srcIn, colorBlendMode: BlendMode.srcIn,
errorBuilder: (_, __, ___) => Icon( errorBuilder: (_, _, _) => Icon(
icon, icon,
size: IconSize.small + 1, size: IconSize.small + 1,
color: iconColor, color: iconColor,
@@ -2732,7 +2732,7 @@ class _ModernChatInputState extends ConsumerState<ModernChatInput>
fit: BoxFit.cover, fit: BoxFit.cover,
color: iconUrl.endsWith('.svg') ? iconColor : null, color: iconUrl.endsWith('.svg') ? iconColor : null,
colorBlendMode: BlendMode.srcIn, colorBlendMode: BlendMode.srcIn,
errorBuilder: (_, __, ___) => Icon( errorBuilder: (_, _, _) => Icon(
Platform.isIOS ? CupertinoIcons.sparkles : Icons.auto_awesome, Platform.isIOS ? CupertinoIcons.sparkles : Icons.auto_awesome,
color: iconColor, color: iconColor,
size: IconSize.modal, size: IconSize.modal,