refactor: Enhance onboarding process in chat and app startup providers

- Integrated autofocus management for the composer in both chat and onboarding contexts to improve user experience.
- Added error handling for focus management to ensure smooth onboarding transitions.
- Updated modal bottom sheet handling to restore autofocus state after onboarding completion, enhancing usability across the app.
This commit is contained in:
cogwheel0
2025-10-19 21:10:10 +05:30
parent 42efbe8fc5
commit 27bfde8f95
3 changed files with 30 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ import '../services/background_streaming_handler.dart';
import '../services/persistent_streaming_service.dart';
import '../services/socket_service.dart';
import '../../features/onboarding/views/onboarding_sheet.dart';
import '../../features/chat/providers/chat_providers.dart';
import '../../shared/theme/theme_extensions.dart';
import '../services/connectivity_service.dart';
import '../utils/debug_logger.dart';
@@ -534,8 +535,16 @@ Future<void> _maybeShowOnboarding(Ref ref) async {
final navContext = NavigationService.navigatorKey.currentContext;
if (navContext == null) return;
try {
ref.read(composerAutofocusEnabledProvider.notifier).set(false);
} catch (_) {}
try {
FocusManager.instance.primaryFocus?.unfocus();
SystemChannels.textInput.invokeMethod('TextInput.hide');
} catch (_) {}
// Show onboarding sheet
showModalBottomSheet(
final sheetFuture = showModalBottomSheet(
context: navContext,
backgroundColor: Colors.transparent,
isScrollControlled: true,
@@ -550,6 +559,11 @@ Future<void> _maybeShowOnboarding(Ref ref) async {
child: const OnboardingSheet(),
),
);
sheetFuture.whenComplete(() {
try {
ref.read(composerAutofocusEnabledProvider.notifier).set(true);
} catch (_) {}
});
await storage.setOnboardingSeen(true);
});