Repository navigation
Expand file tree
/
Copy pathmain.dart
More file actions
141 lines (133 loc) · 5.54 KB
/
Copy pathmain.dart
File metadata and controls
141 lines (133 loc) · 5.54 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import 'package:aelf_flutter/app_screens/aelf_home_page.dart';
import 'package:aelf_flutter/utils/bibleDbProvider.dart';
import 'package:aelf_flutter/states/currentZoomState.dart';
import 'package:aelf_flutter/states/liturgyState.dart';
import 'package:aelf_flutter/states/pageState.dart';
import 'package:aelf_flutter/states/featureFlagsState.dart';
import 'package:aelf_flutter/states/selectedCelebrationState.dart';
import 'package:aelf_flutter/states/biblePositionState.dart';
import 'package:aelf_flutter/utils/settings.dart';
import 'package:aelf_flutter/utils/theme_provider.dart';
import 'dart:io' show Platform;
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:aelf_flutter/app_screens/bible_lists_screen.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:marionette_flutter/marionette_flutter.dart';
import 'package:provider/provider.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
void main() {
// Initialize Marionette only in debug mode
if (kDebugMode) {
MarionetteBinding.ensureInitialized();
} else {
WidgetsFlutterBinding.ensureInitialized();
}
runAelfApp();
}
/// Everything [main] does once a binding is installed: system UI mode, the
/// widget tree, and the sqflite FFI setup the Bible database needs.
///
/// Split out of [main] because the integration suite installs its own binding
/// (`IntegrationTestWidgetsFlutterBinding`) before the app starts, and
/// initializing a second binding trips an assertion in `BindingBase`. Those
/// tests call this directly; nothing else should.
Future<void> runAelfApp() async {
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: [SystemUiOverlay.bottom],
);
}
// Read before the first frame so providers gating UI on this flag (e.g.
// FeatureFlagsState / the "Mode défilement" toggle) start with the right
// value instead of flashing while their own async load is still pending.
final offlineLiturgyEnabled = await getFeatureOfflineLiturgy();
runApp(MyApp(initialOfflineLiturgyEnabled: offlineLiturgyEnabled));
// Initialize FFI
sqfliteFfiInit();
// Change the default factory
databaseFactory = databaseFactoryFfi;
// Initialize database
ensureDatabase();
}
class MyApp extends StatelessWidget {
final bool? initialOfflineLiturgyEnabled;
MyApp({Key? key, this.initialOfflineLiturgyEnabled}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
// Prevent screen to be locked
if (defaultTargetPlatform != TargetPlatform.linux) {
WakelockPlus.enable();
}
return MultiProvider(
providers: [
ChangeNotifierProvider<CurrentZoom>(create: (_) => CurrentZoom()),
ChangeNotifierProvider<LiturgyState>(create: (_) => LiturgyState()),
ChangeNotifierProvider<PageState>(create: (_) => PageState()),
ChangeNotifierProvider<FeatureFlagsState>(
create: (_) => FeatureFlagsState(
initialOfflineLiturgyEnabled: initialOfflineLiturgyEnabled)),
ChangeNotifierProvider<SelectedCelebrationState>(
create: (_) => SelectedCelebrationState()),
ChangeNotifierProvider<BiblePositionState>(
create: (_) => BiblePositionState())
],
child: ChangeNotifierProvider(
create: (_) => ThemeNotifier(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
onGenerateRoute: (settings) {
// If you push the PassArguments route
if (settings.name == PassArgumentsScreen.routeName) {
// Cast the arguments to the correct type: ScreenArguments.
final ScreenArguments? args =
settings.arguments as ScreenArguments?;
// Then, extract the required data from the arguments and
// pass the data to the correct screen.
return MaterialPageRoute(
builder: (context) {
return PassArgumentsScreen(
title: args!.title,
message: args.message,
);
},
);
}
return null;
},
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
DefaultCupertinoLocalizations.delegate
],
supportedLocales: [
const Locale('en', 'US'),
const Locale('fr', 'FR'),
],
// Use builder to inject the dynamic theme without rebuilding MaterialApp.
// This prevents open overlays (popups, dialogs) from being dismissed
// when the theme changes.
builder: (context, child) {
return Consumer<ThemeNotifier>(
builder: (context, notifier, _) => Theme(
data: notifier.currentTheme,
child: child!,
),
);
},
// Disable dynamic font size as it is now possible to pinch to zoom
// source https://stackoverflow.com/a/54489680
home: AelfHomePage()),
),
);
}
}
void ensureDatabase() async {
await BibleDbSqfProvider.instance.ensureDatabase();
}