buildRootWidget method
Implementation
Future<Widget> buildRootWidget() async {
AppBootstrap._current = this;
/// Set the resolver
final serviceResolver = await injection.initializeResolver();
final infoX = await localization.initializeInfoX();
final _appInfo = await appInfo.loadAppInfo(identifier, appTitle);
_mainLog.info("---------------------------------------- ");
_mainLog.info("---------------------------------------- ");
_mainLog.info("");
_mainLog.info("${_appInfo.appName}");
_mainLog.info("Package: ${_appInfo.packageName}");
_mainLog.info("Version: ${_appInfo.appVersion}");
if (_appInfo.buildNumber.isNotNullOrBlank) {
_mainLog.info("Package: ${_appInfo.buildNumber}");
}
_mainLog.info("");
_mainLog.info("---------------------------------------- ");
_mainLog.info("---------------------------------------- ");
var initProfile = await auth.getInitialUser();
_mainLog.info("");
_mainLog.info("Starting user: ${initProfile?.profile?.name ?? 'None'}");
await routing.initializeRoutes();
_mainLog.info("Fetching device info...");
var _deviceInfo = await deviceInfo.loadDeviceInfo();
_mainLog.info("Fetched device: ${_deviceInfo.deviceType}");
final _userPrefs = userPrefs.initializePreferences(identifier);
final analytics = analyticsInit.initializeAnalytics();
try {
await analytics.initialize(
_deviceInfo,
_appInfo,
_userPrefs,
);
_mainLog.info("Initialized Firebase Analytics");
} catch (e) {
_mainLog.warning("Unable to initialize Firebase analytics: $e");
}
final authState = auth.initializeState(initProfile, appErrors);
if (onPreLogout != null) {
authState.onPreLogout(onPreLogout!);
}
this.lifecycleInit = LifecycleInit(
_deviceInfo,
authState,
analytics,
routing,
_appInfo,
_userPrefs,
null,
);
var appContextEvents = AppContextEvents();
/// Register app events stream
if (initWithinNavigator != null) {
appContextEvents.doWithAppContext(initWithinNavigator!);
}
final res = await completeStage1?.call(lifecycleInit);
Widget? builtApp;
final sunnyLocations = await localization.initializeLocalization(infoX);
return Builder(
builder: (context) {
if (builtApp == null) {
serviceResolver.registerSingleton<AppContextEvents>(
context, appContextEvents);
serviceResolver.registerSingleton<BuildContextResolver>(
context, serviceResolver);
}
return builtApp ??= serviceResolver.register(
context,
[
Inst.constant(infoX),
Inst.constant(sunnyLocations),
],
child: MultiProvider(
key: Key("mainTop"),
providers: [
Provider.value(
value: appContextEvents,
updateShouldNotify: never,
),
Provider.value(value: infoX, updateShouldNotify: never),
Provider.value(value: sunnyLocations, updateShouldNotify: never),
Provider.value(value: this, updateShouldNotify: never),
Provider.value(value: _deviceInfo, updateShouldNotify: never),
Provider.value(value: _appInfo, updateShouldNotify: never),
Provider.value(value: _userPrefs, updateShouldNotify: never),
Provider.value(value: lifecycleInit, updateShouldNotify: never),
// Provider.value(value: help, updateShouldNotify: never),
Provider.value(value: router, updateShouldNotify: never),
Provider.value(
value: lifecycleInit!.authState, updateShouldNotify: never),
Provider<IAuthState>.value(
value: lifecycleInit!.authState, updateShouldNotify: never),
if (res is SingleChildWidget) res,
],
child: buildOuterContext(
AppWidgets(
deviceInfo: _deviceInfo,
appInfo: _appInfo,
isChangeBrightness: isChangeBrightness,
),
),
),
);
},
);
}