~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.
a0261f1f
—
pyrossh 2 years ago
fix chapter model
- lib/screens/chapter_view_screen.dart +8 -7
- lib/state.dart +36 -38
lib/screens/chapter_view_screen.dart
CHANGED
|
@@ -32,22 +32,23 @@ class ChapterViewScreen extends StatelessWidget {
|
|
|
32
32
|
// );
|
|
33
33
|
// },
|
|
34
34
|
// ),
|
|
35
|
+
final model = ChapterViewModel(
|
|
36
|
+
book: book,
|
|
37
|
+
chapter: chapter,
|
|
38
|
+
selectedVerses: [],
|
|
39
|
+
);
|
|
35
40
|
return ChangeNotifierProvider(
|
|
36
|
-
create: (context) =>
|
|
41
|
+
create: (context) => model,
|
|
37
|
-
book: book,
|
|
38
|
-
chapter: chapter,
|
|
39
|
-
selectedVerses: [],
|
|
40
|
-
),
|
|
41
42
|
child: Scaffold(
|
|
42
43
|
backgroundColor: Theme.of(context).colorScheme.background,
|
|
43
44
|
bottomSheet: const ActionsBar(),
|
|
44
45
|
body: SafeArea(
|
|
45
46
|
child: SwipeDetector(
|
|
46
47
|
onSwipeLeft: (offset) {
|
|
47
|
-
onNext(context, book, chapter);
|
|
48
|
+
model.onNext(context, book, chapter);
|
|
48
49
|
},
|
|
49
50
|
onSwipeRight: (offset) {
|
|
50
|
-
onPrevious(context, book, chapter);
|
|
51
|
+
model.onPrevious(context, book, chapter);
|
|
51
52
|
},
|
|
52
53
|
child: Row(
|
|
53
54
|
children: [
|
lib/state.dart
CHANGED
|
@@ -132,6 +132,42 @@ class ChapterViewModel extends ChangeNotifier {
|
|
|
132
132
|
prefs.setInt("chapter", chapter);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
navigateBookChapter(BuildContext context, int book, int chapter, TextDirection? dir) {
|
|
136
|
+
Navigator.of(context).push(
|
|
137
|
+
createSlideRoute(
|
|
138
|
+
context: context,
|
|
139
|
+
slideDir: dir,
|
|
140
|
+
page: ChapterViewScreen(book: book, chapter: chapter),
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
onNext(BuildContext context, int book, int chapter) {
|
|
146
|
+
final selectedBible = AppModel.ofEvent(context).bible;
|
|
147
|
+
final selectedBook = selectedBible.books[book];
|
|
148
|
+
if (selectedBook.chapters.length > chapter + 1) {
|
|
149
|
+
navigateBookChapter(context, selectedBook.index, chapter + 1, TextDirection.ltr);
|
|
150
|
+
} else {
|
|
151
|
+
if (selectedBook.index + 1 < selectedBible.books.length) {
|
|
152
|
+
final nextBook = selectedBible.books[selectedBook.index + 1];
|
|
153
|
+
navigateBookChapter(context, nextBook.index, 0, TextDirection.ltr);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
onPrevious(BuildContext context, int book, int chapter) {
|
|
159
|
+
final selectedBible = AppModel.ofEvent(context).bible;
|
|
160
|
+
final selectedBook = selectedBible.books[book];
|
|
161
|
+
if (chapter - 1 >= 0) {
|
|
162
|
+
navigateBookChapter(context, selectedBook.index, chapter - 1, TextDirection.rtl);
|
|
163
|
+
} else {
|
|
164
|
+
if (selectedBook.index - 1 >= 0) {
|
|
165
|
+
final prevBook = selectedBible.books[selectedBook.index - 1];
|
|
166
|
+
navigateBookChapter(context, prevBook.index, prevBook.chapters.length - 1, TextDirection.rtl);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
135
171
|
bool hasSelectedVerses() {
|
|
136
172
|
return selectedVerses.isNotEmpty;
|
|
137
173
|
}
|
|
@@ -224,44 +260,6 @@ createSlideRoute({required BuildContext context, TextDirection? slideDir, requir
|
|
|
224
260
|
);
|
|
225
261
|
}
|
|
226
262
|
|
|
227
|
-
navigateBookChapter(BuildContext context, int book, int chapter, TextDirection? dir) {
|
|
228
|
-
// TODO: add bible param here maybe
|
|
229
|
-
// route: /bible/book/chapter
|
|
230
|
-
Navigator.of(context).push(
|
|
231
|
-
createSlideRoute(
|
|
232
|
-
context: context,
|
|
233
|
-
slideDir: dir,
|
|
234
|
-
page: ChapterViewScreen(book: book, chapter: chapter),
|
|
235
|
-
),
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
onNext(BuildContext context, int book, int chapter) {
|
|
240
|
-
final selectedBible = AppModel.of(context).bible;
|
|
241
|
-
final selectedBook = selectedBible.books[book];
|
|
242
|
-
if (selectedBook.chapters.length > chapter + 1) {
|
|
243
|
-
navigateBookChapter(context, selectedBook.index, chapter + 1, TextDirection.ltr);
|
|
244
|
-
} else {
|
|
245
|
-
if (selectedBook.index + 1 < selectedBible.books.length) {
|
|
246
|
-
final nextBook = selectedBible.books[selectedBook.index + 1];
|
|
247
|
-
navigateBookChapter(context, nextBook.index, 0, TextDirection.ltr);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
onPrevious(BuildContext context, int book, int chapter) {
|
|
253
|
-
final selectedBible = AppModel.of(context).bible;
|
|
254
|
-
final selectedBook = selectedBible.books[book];
|
|
255
|
-
if (chapter - 1 >= 0) {
|
|
256
|
-
navigateBookChapter(context, selectedBook.index, chapter - 1, TextDirection.rtl);
|
|
257
|
-
} else {
|
|
258
|
-
if (selectedBook.index - 1 >= 0) {
|
|
259
|
-
final prevBook = selectedBible.books[selectedBook.index - 1];
|
|
260
|
-
navigateBookChapter(context, prevBook.index, prevBook.chapters.length - 1, TextDirection.rtl);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
263
|
getBibleFromAsset(String file) async {
|
|
266
264
|
final bytes = await rootBundle.load("assets/bibles/$file.txt");
|
|
267
265
|
return getBibleFromText(utf8.decode(bytes.buffer.asUint8List(), allowMalformed: false));
|