dart format
This commit is contained in:
+146
-119
@@ -40,19 +40,28 @@ Future<void> main() async {
|
||||
log('MarianumMobile started');
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
void addCertificateAsTrusted(ByteData certificate) =>
|
||||
SecurityContext.defaultContext.setTrustedCertificatesBytes(certificate.buffer.asUint8List());
|
||||
void addCertificateAsTrusted(ByteData certificate) => SecurityContext
|
||||
.defaultContext
|
||||
.setTrustedCertificatesBytes(certificate.buffer.asUint8List());
|
||||
|
||||
final initialisationTasks = [
|
||||
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform)
|
||||
.then<void>((_) {})
|
||||
.onError((error, _) => log('Error initializing Firebase: $error')),
|
||||
PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem').then(addCertificateAsTrusted),
|
||||
PlatformAssetBundle().load('assets/ca/lets-encrypt-r10.pem').then(addCertificateAsTrusted),
|
||||
PlatformAssetBundle().load('assets/ca/lets-encrypt-r13.pem').then(addCertificateAsTrusted),
|
||||
PlatformAssetBundle()
|
||||
.load('assets/ca/lets-encrypt-r3.pem')
|
||||
.then(addCertificateAsTrusted),
|
||||
PlatformAssetBundle()
|
||||
.load('assets/ca/lets-encrypt-r10.pem')
|
||||
.then(addCertificateAsTrusted),
|
||||
PlatformAssetBundle()
|
||||
.load('assets/ca/lets-encrypt-r13.pem')
|
||||
.then(addCertificateAsTrusted),
|
||||
Future(() async {
|
||||
final storage = await HydratedStorage.build(
|
||||
storageDirectory: HydratedStorageDirectory((await getTemporaryDirectory()).path),
|
||||
storageDirectory: HydratedStorageDirectory(
|
||||
(await getTemporaryDirectory()).path,
|
||||
),
|
||||
);
|
||||
HydratedBloc.storage = storage;
|
||||
}),
|
||||
@@ -71,27 +80,30 @@ Future<void> main() async {
|
||||
|
||||
if (kReleaseMode) {
|
||||
ErrorWidget.builder = (error) => Material(
|
||||
color: Colors.white,
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.phonelink_erase_rounded, size: 40),
|
||||
const SizedBox(height: 12),
|
||||
Text(error.toStringShort(), textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
),
|
||||
color: Colors.white,
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.phonelink_erase_rounded, size: 40),
|
||||
const SizedBox(height: 12),
|
||||
Text(error.toStringShort(), textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
);
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Capture uncaught Flutter and platform errors so they show up in logs
|
||||
// instead of being silently swallowed.
|
||||
FlutterError.onError = (details) {
|
||||
log('Uncaught Flutter error: ${details.exception}', stackTrace: details.stack);
|
||||
log(
|
||||
'Uncaught Flutter error: ${details.exception}',
|
||||
stackTrace: details.stack,
|
||||
);
|
||||
FlutterError.presentError(details);
|
||||
};
|
||||
PlatformDispatcher.instance.onError = (error, stack) {
|
||||
@@ -104,9 +116,13 @@ Future<void> main() async {
|
||||
MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<SettingsCubit>(create: (_) => SettingsCubit()),
|
||||
BlocProvider<AccountBloc>(create: (_) => AccountBloc(
|
||||
initialStatus: AccountData().isPopulated() ? AccountStatus.loggedIn : AccountStatus.loggedOut,
|
||||
)),
|
||||
BlocProvider<AccountBloc>(
|
||||
create: (_) => AccountBloc(
|
||||
initialStatus: AccountData().isPopulated()
|
||||
? AccountStatus.loggedIn
|
||||
: AccountStatus.loggedOut,
|
||||
),
|
||||
),
|
||||
BlocProvider<BreakerBloc>(create: (_) => BreakerBloc()),
|
||||
BlocProvider<ChatListBloc>(create: (_) => ChatListBloc()),
|
||||
BlocProvider<ChatBloc>(create: (_) => ChatBloc()),
|
||||
@@ -120,7 +136,9 @@ Future<void> main() async {
|
||||
class Main extends StatefulWidget {
|
||||
const Main({super.key});
|
||||
|
||||
static PersistentTabController bottomNavigator = PersistentTabController(initialIndex: 0);
|
||||
static PersistentTabController bottomNavigator = PersistentTabController(
|
||||
initialIndex: 0,
|
||||
);
|
||||
|
||||
@override
|
||||
State<Main> createState() => _MainState();
|
||||
@@ -134,107 +152,116 @@ class _MainState extends State<Main> {
|
||||
|
||||
AccountData().waitForPopulation().then((value) {
|
||||
if (!mounted) return;
|
||||
context.read<AccountBloc>().setStatus(value ? AccountStatus.loggedIn : AccountStatus.loggedOut);
|
||||
context.read<AccountBloc>().setStatus(
|
||||
value ? AccountStatus.loggedIn : AccountStatus.loggedOut,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: BlocBuilder<SettingsCubit, Settings>(
|
||||
builder: (context, settings) {
|
||||
final devToolsSettings = settings.devToolsSettings;
|
||||
return MaterialApp(
|
||||
showPerformanceOverlay: devToolsSettings.showPerformanceOverlay,
|
||||
checkerboardOffscreenLayers: devToolsSettings.checkerboardOffscreenLayers,
|
||||
checkerboardRasterCacheImages: devToolsSettings.checkerboardRasterCacheImages,
|
||||
debugShowCheckedModeBanner: false,
|
||||
localizationsDelegates: const [
|
||||
...GlobalMaterialLocalizations.delegates,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('de'), Locale('en')],
|
||||
locale: const Locale('de'),
|
||||
title: 'Marianum Fulda',
|
||||
themeMode: settings.appTheme,
|
||||
theme: LightAppTheme.theme,
|
||||
darkTheme: DarkAppTheme.theme,
|
||||
// Brand-colored backdrop behind every route. During the logout
|
||||
// home-swap and route pop animations the framework can briefly
|
||||
// expose the layer below the topmost Scaffold; without this
|
||||
// the dark Material default shows through and the user sees a
|
||||
// black flash.
|
||||
builder: (context, child) => ColoredBox(
|
||||
color: LightAppTheme.marianumRed,
|
||||
child: child ?? const SizedBox.shrink(),
|
||||
),
|
||||
home: LoaderOverlay(
|
||||
child: Breaker(
|
||||
breaker: BreakerArea.global,
|
||||
child: BlocConsumer<AccountBloc, AccountState>(
|
||||
listenWhen: (previous, current) => previous.status != current.status,
|
||||
listener: (context, accountState) {
|
||||
if (accountState.status != AccountStatus.loggedOut) return;
|
||||
// Routes pushed via AppRoutes (e.g. Settings) live on the
|
||||
// root navigator and survive the home swap below, so they
|
||||
// would still cover the Login screen after logout. Pop
|
||||
// them here so the user immediately sees Login.
|
||||
final navigator = Navigator.of(context);
|
||||
if (navigator.canPop()) {
|
||||
navigator.popUntil((route) => route.isFirst);
|
||||
}
|
||||
// Capture bloc references before the post-frame callback
|
||||
// — by the time it runs the dialog/Settings context is
|
||||
// gone but this listener context is still valid.
|
||||
final settingsCubit = context.read<SettingsCubit>();
|
||||
final timetableBloc = context.read<TimetableBloc>();
|
||||
final chatListBloc = context.read<ChatListBloc>();
|
||||
final chatBloc = context.read<ChatBloc>();
|
||||
final breakerBloc = context.read<BreakerBloc>();
|
||||
// Defer the actual wipe until after this frame so the
|
||||
// App tree (TimetableBloc/ChatListBloc watchers etc.)
|
||||
// is already torn down. Resetting blocs while App is
|
||||
// still in front caused a black-frame race.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
unawaited(_wipeUserState(
|
||||
settingsCubit: settingsCubit,
|
||||
timetableBloc: timetableBloc,
|
||||
chatListBloc: chatListBloc,
|
||||
chatBloc: chatBloc,
|
||||
breakerBloc: breakerBloc,
|
||||
));
|
||||
});
|
||||
},
|
||||
builder: (context, accountState) {
|
||||
switch (accountState.status) {
|
||||
case AccountStatus.loggedIn:
|
||||
return const App();
|
||||
case AccountStatus.loggedOut:
|
||||
return const Login();
|
||||
case AccountStatus.undefined:
|
||||
return Scaffold(
|
||||
backgroundColor: LightAppTheme.marianumRed,
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
AppProgressIndicator.large(color: Colors.white),
|
||||
SizedBox(height: 16),
|
||||
Text('Konto wird geladen…',
|
||||
style: TextStyle(color: Colors.white)),
|
||||
],
|
||||
textDirection: TextDirection.ltr,
|
||||
child: BlocBuilder<SettingsCubit, Settings>(
|
||||
builder: (context, settings) {
|
||||
final devToolsSettings = settings.devToolsSettings;
|
||||
return MaterialApp(
|
||||
showPerformanceOverlay: devToolsSettings.showPerformanceOverlay,
|
||||
checkerboardOffscreenLayers:
|
||||
devToolsSettings.checkerboardOffscreenLayers,
|
||||
checkerboardRasterCacheImages:
|
||||
devToolsSettings.checkerboardRasterCacheImages,
|
||||
debugShowCheckedModeBanner: false,
|
||||
localizationsDelegates: const [
|
||||
...GlobalMaterialLocalizations.delegates,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('de'), Locale('en')],
|
||||
locale: const Locale('de'),
|
||||
title: 'Marianum Fulda',
|
||||
themeMode: settings.appTheme,
|
||||
theme: LightAppTheme.theme,
|
||||
darkTheme: DarkAppTheme.theme,
|
||||
// Brand-colored backdrop behind every route. During the logout
|
||||
// home-swap and route pop animations the framework can briefly
|
||||
// expose the layer below the topmost Scaffold; without this
|
||||
// the dark Material default shows through and the user sees a
|
||||
// black flash.
|
||||
builder: (context, child) => ColoredBox(
|
||||
color: LightAppTheme.marianumRed,
|
||||
child: child ?? const SizedBox.shrink(),
|
||||
),
|
||||
home: LoaderOverlay(
|
||||
child: Breaker(
|
||||
breaker: BreakerArea.global,
|
||||
child: BlocConsumer<AccountBloc, AccountState>(
|
||||
listenWhen: (previous, current) =>
|
||||
previous.status != current.status,
|
||||
listener: (context, accountState) {
|
||||
if (accountState.status != AccountStatus.loggedOut) return;
|
||||
// Routes pushed via AppRoutes (e.g. Settings) live on the
|
||||
// root navigator and survive the home swap below, so they
|
||||
// would still cover the Login screen after logout. Pop
|
||||
// them here so the user immediately sees Login.
|
||||
final navigator = Navigator.of(context);
|
||||
if (navigator.canPop()) {
|
||||
navigator.popUntil((route) => route.isFirst);
|
||||
}
|
||||
// Capture bloc references before the post-frame callback
|
||||
// — by the time it runs the dialog/Settings context is
|
||||
// gone but this listener context is still valid.
|
||||
final settingsCubit = context.read<SettingsCubit>();
|
||||
final timetableBloc = context.read<TimetableBloc>();
|
||||
final chatListBloc = context.read<ChatListBloc>();
|
||||
final chatBloc = context.read<ChatBloc>();
|
||||
final breakerBloc = context.read<BreakerBloc>();
|
||||
// Defer the actual wipe until after this frame so the
|
||||
// App tree (TimetableBloc/ChatListBloc watchers etc.)
|
||||
// is already torn down. Resetting blocs while App is
|
||||
// still in front caused a black-frame race.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
unawaited(
|
||||
_wipeUserState(
|
||||
settingsCubit: settingsCubit,
|
||||
timetableBloc: timetableBloc,
|
||||
chatListBloc: chatListBloc,
|
||||
chatBloc: chatBloc,
|
||||
breakerBloc: breakerBloc,
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
builder: (context, accountState) {
|
||||
switch (accountState.status) {
|
||||
case AccountStatus.loggedIn:
|
||||
return const App();
|
||||
case AccountStatus.loggedOut:
|
||||
return const Login();
|
||||
case AccountStatus.undefined:
|
||||
return Scaffold(
|
||||
backgroundColor: LightAppTheme.marianumRed,
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
AppProgressIndicator.large(color: Colors.white),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Konto wird geladen…',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _wipeUserState({
|
||||
|
||||
Reference in New Issue
Block a user