Skip to content

Commit 040dd8a

Browse files
authored
fix: ensure system info is loaded before MainShell builds (#1105)
CallerIdSettingsRepository.create and another provider create: in main_shell.dart call getLocalSystemInfo() synchronously. If system info is absent (cleared during session cleanup after FGS failure, or never fetched in this session) the provider throws StateError and crashes the app. Add a getSystemInfo(cacheFirst) call to onMainShellRouteGuardNavigation, executed after the auth check and before navigation resolves. If system info cannot be loaded — no cache and network unreachable — redirect to the login screen. This prevents the crash observed on Xiaomi after FGS recovery: CallerIdSettingsRepository.create → getLocalSystemInfo() → StateError: "No system info in cache" (main_shell.dart:257)
1 parent 89fb6ec commit 040dd8a

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

lib/app/router/app_router.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:webtrit_phone/blocs/app/app_bloc.dart';
1111
import 'package:webtrit_phone/data/data.dart';
1212
import 'package:webtrit_phone/features/features.dart';
1313
import 'package:webtrit_phone/models/models.dart';
14+
import 'package:webtrit_phone/repositories/repositories.dart';
1415
import 'package:webtrit_phone/resolvers/resolvers.dart';
1516

1617
import 'deeplinks.dart';
@@ -27,6 +28,7 @@ class AppRouter extends RootStackRouter {
2728
AppRouter(
2829
this._appBloc,
2930
this._appPermissions,
31+
this._systemInfoRepository,
3032
EmbeddedData? launchEmbeddedData,
3133
BottomMenuConfig bottomMenuFeature,
3234
InitialTabResolver initialTabResolver,
@@ -40,6 +42,7 @@ class AppRouter extends RootStackRouter {
4042

4143
final AppBloc _appBloc;
4244
final AppPermissions _appPermissions;
45+
final SystemInfoRepository _systemInfoRepository;
4346

4447
late EmbeddedData? _launchEmbeddedData;
4548
late BottomMenuConfig _bottomMenuFeature;
@@ -340,6 +343,25 @@ class AppRouter extends RootStackRouter {
340343
return;
341344
}
342345

346+
// Ensure system info is in cache before MainShell builds.
347+
// Several provider create: callbacks call getLocalSystemInfo() synchronously;
348+
// without this guard the app crashes if system info was cleared (e.g. during
349+
// session cleanup after an FGS failure) or was never fetched in this session.
350+
try {
351+
final systemInfo = await _systemInfoRepository.getSystemInfo(fetchPolicy: FetchPolicy.cacheFirst);
352+
if (systemInfo == null) {
353+
_logger.warning('onMainShellRouteGuardNavigation: system info unavailable, redirecting to login');
354+
resolver.next(false);
355+
router.replaceAll([LoginRouterPageRoute(launchEmbeddedData: _launchEmbeddedData)]);
356+
return;
357+
}
358+
} catch (e, s) {
359+
_logger.severe('onMainShellRouteGuardNavigation: failed to load system info', e, s);
360+
resolver.next(false);
361+
router.replaceAll([LoginRouterPageRoute(launchEmbeddedData: _launchEmbeddedData)]);
362+
return;
363+
}
364+
343365
// Enforce mandatory legal agreements and system permissions.
344366
final contactsSourceTypes = _bottomMenuFeature.getTabEnabled<ContactsBottomMenuTab>()?.contactSourceTypes;
345367
final isLocalContactsEnabled = contactsSourceTypes?.contains(ContactSourceType.local) ?? false;

lib/app/view/app.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class _AppState extends State<App> {
6969
appRouter = AppRouter(
7070
appBloc,
7171
context.read<AppPermissions>(),
72+
context.read<SystemInfoRepository>(),
7273
featureAccess.loginConfig.launchLoginPage,
7374
featureAccess.bottomMenuConfig,
7475
initialTabResolver,

0 commit comments

Comments
 (0)