1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:orgro/l10n/app_localizations.dart';
import 'package:orgro/src/agenda.dart';
import 'package:orgro/src/background_tasks.dart';
import 'package:orgro/src/cache.dart';
import 'package:orgro/src/components/remembered_files.dart';
import 'package:orgro/src/debug.dart';
import 'package:orgro/src/entitlements.dart';
import 'package:orgro/src/pages/pages.dart';
import 'package:orgro/src/preferences.dart';
import 'package:orgro/src/quick_actions.dart';
import 'package:orgro/src/routes/routes.dart';
import 'package:orgro/theme.dart';
final startKey = GlobalKey<StartPageState>();
void main() async {
LicenseRegistry.addLicense(() async* {
yield LicenseEntryWithLineBreaks([
'google_fonts',
], await rootBundle.loadString('assets/fonts/OFL.txt'));
yield LicenseEntryWithLineBreaks([
'LineReader',
], await rootBundle.loadString('assets/licenses/LICENSE-LineReader.txt'));
});
if (kReleaseMode) {
// Disable debug printing for release builds
debugPrint = (_, {wrapWidth}) {};
}
runApp(buildApp());
try {
await clearTemporaryAttachments();
} catch (e, s) {
logError(e, s);
}
try {
await cleanNotficationsLockfile();
} catch (e, s) {
logError(e, s);
}
}
Widget buildApp({bool isTest = false}) => ExecutionMode(
isTest: isTest,
child: UserEntitlements(
child: Preferences(
isTest: isTest,
child: RememberedFiles(child: const _MyApp()),
),
),
);
class ExecutionMode extends InheritedWidget {
static ExecutionMode of(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ExecutionMode>()!;
const ExecutionMode({required this.isTest, super.key, required super.child});
final bool isTest;
@override
bool updateShouldNotify(ExecutionMode oldWidget) =>
isTest != oldWidget.isTest;
}
// Not the "real" splash screen; just something to cover the blank while waiting
// for Preferences to load
class _Splash extends StatelessWidget {
const _Splash();
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: double.infinity,
color: orgroPrimaryColor,
);
}
}
class _MyApp extends StatelessWidget {
const _MyApp();
@override
Widget build(BuildContext context) {
return MaterialApp(
restorationScopeId: 'orgro_root',
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
debugShowCheckedModeBanner: !kScreenshotMode,
onGenerateTitle: (context) => AppLocalizations.of(context)!.appTitle,
theme: orgroLightTheme,
darkTheme: orgroDarkTheme,
themeMode: Preferences.of(context, PrefsAspect.appearance).themeMode,
home: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: Preferences.of(context, PrefsAspect.init).isInitialized
? QuickActions(
child: BackgroundTasks(child: StartPage(key: startKey)),
)
: const _Splash(),
transitionBuilder: (child, animation) =>
FadeTransition(opacity: animation, child: child),
),
onGenerateRoute: onGenerateRoute,
);
}
}