~repos /only-bible-app
git clone https://pyrossh.dev/repos/only-bible-app.git
The only bible app you will ever need. No ads. No in-app purchases. No distractions.
977436a8
—
pyrossh 2 years ago
add load bible
- lib/screens/bible_select_screen.dart +5 -1
- lib/state.dart +15 -19
lib/screens/bible_select_screen.dart
CHANGED
|
@@ -10,6 +10,7 @@ class BibleSelectScreen extends StatelessWidget {
|
|
|
10
10
|
|
|
11
11
|
@override
|
|
12
12
|
Widget build(BuildContext context) {
|
|
13
|
+
final model = AppModel.of(context);
|
|
13
14
|
return ScaffoldMenu(
|
|
14
15
|
child: CustomScrollView(
|
|
15
16
|
slivers: [
|
|
@@ -20,7 +21,10 @@ class BibleSelectScreen extends StatelessWidget {
|
|
|
20
21
|
bibles.map((bible) {
|
|
21
22
|
return TextButton(
|
|
22
23
|
child: Text(bible.name),
|
|
24
|
+
onPressed: () {
|
|
23
|
-
|
|
25
|
+
model.changeBible(context, bible.id);
|
|
26
|
+
Navigator.of(context).pop();
|
|
27
|
+
},
|
|
24
28
|
);
|
|
25
29
|
}),
|
|
26
30
|
),
|
lib/state.dart
CHANGED
|
@@ -36,13 +36,7 @@ class AppModel extends ChangeNotifier {
|
|
|
36
36
|
darkMode = prefs.getBool("darkMode") ?? false;
|
|
37
37
|
fontBold = prefs.getBool("fontBold") ?? false;
|
|
38
38
|
fontSizeDelta = prefs.getInt("fontSizeDelta") ?? 0;
|
|
39
|
-
final selectedBible = bibles.firstWhere((it) => it.id == bibleId);
|
|
40
|
-
final books = await getBibleFromAsset(selectedBible.name);
|
|
41
|
-
bible =
|
|
39
|
+
bible = await loadBible(bibleId);
|
|
42
|
-
id: selectedBible.id,
|
|
43
|
-
name: selectedBible.name,
|
|
44
|
-
books: books,
|
|
45
|
-
);
|
|
46
40
|
// await Future.delayed(Duration(seconds: 3));
|
|
47
41
|
final book = prefs.getInt("book") ?? 0;
|
|
48
42
|
final chapter = prefs.getInt("chapter") ?? 0;
|
|
@@ -50,13 +44,21 @@ class AppModel extends ChangeNotifier {
|
|
|
50
44
|
return (book, chapter);
|
|
51
45
|
}
|
|
52
46
|
|
|
47
|
+
Future<Bible> loadBible(int id) async {
|
|
48
|
+
final selectedBible = bibles.firstWhere((it) => it.id == id);
|
|
49
|
+
final books = await getBibleFromAsset(selectedBible.name);
|
|
50
|
+
return Bible.withBooks(
|
|
53
|
-
|
|
51
|
+
id: selectedBible.id,
|
|
54
|
-
|
|
52
|
+
name: selectedBible.name,
|
|
55
|
-
|
|
53
|
+
books: books,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
+
changeBible(BuildContext context, int id) async {
|
|
57
|
-
|
|
58
|
+
// TODO: maybe use a future as the bible needs to load
|
|
58
|
-
|
|
59
|
+
bible = await loadBible(id);
|
|
59
|
-
|
|
60
|
+
notifyListeners();
|
|
61
|
+
}
|
|
60
62
|
|
|
61
63
|
toggleMode() async {
|
|
62
64
|
darkMode = !darkMode;
|
|
@@ -188,12 +190,6 @@ bool isWide(BuildContext context) {
|
|
|
188
190
|
return width > 600;
|
|
189
191
|
}
|
|
190
192
|
|
|
191
|
-
changeBible(BuildContext context, int i) {
|
|
192
|
-
// TODO: maybe use a future as the bible needs to load
|
|
193
|
-
// loadBible();
|
|
194
|
-
Navigator.of(context).pop();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
193
|
createNoTransitionPageRoute(Widget page) {
|
|
198
194
|
return PageRouteBuilder(
|
|
199
195
|
pageBuilder: (context, _, __) {
|