~repos /only-bible-app

#kotlin#android#ios

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.


0662e02d pyrossh

2 years ago
fix dark mode colors
lib/providers/app_provider.dart CHANGED
@@ -5,6 +5,7 @@ import "package:firebase_storage/firebase_storage.dart";
5
5
  import "package:just_audio/just_audio.dart";
6
6
  import "package:only_bible_app/dialog.dart";
7
7
  import "package:only_bible_app/screens/chapter_view_screen.dart";
8
+ import "package:only_bible_app/theme.dart";
8
9
  import "package:share_plus/share_plus.dart";
9
10
  import "package:flutter_gen/gen_l10n/app_localizations.dart";
10
11
  import "package:flutter/material.dart";
@@ -57,7 +58,9 @@ class AppProvider extends ChangeNotifier {
57
58
  }
58
59
 
59
60
  static AppLocalizations getLocalizations(BuildContext context) {
61
+ return AppProvider.of(context).engTitles
60
- return AppProvider.of(context).engTitles ? lookupAppLocalizations(const Locale("en")) : AppLocalizations.of(context)!;
62
+ ? lookupAppLocalizations(const Locale("en"))
63
+ : AppLocalizations.of(context)!;
61
64
  }
62
65
 
63
66
  save() async {
@@ -383,28 +386,39 @@ class AppProvider extends ChangeNotifier {
383
386
  Navigator.of(context).pop();
384
387
  }
385
388
 
386
- static Color fromHexS(String hexString) {
387
- return Color(int.parse(hexString, radix: 16));
388
- }
389
-
390
- String toHexS(Color c) => '${c.alpha.toRadixString(16).padLeft(2, '0')}'
391
- '${c.red.toRadixString(16).padLeft(2, '0')}'
392
- '${c.green.toRadixString(16).padLeft(2, '0')}'
393
- '${c.blue.toRadixString(16).padLeft(2, '0')}';
394
-
395
389
  Color? getHighlight(Verse v) {
396
390
  final key = "${v.book}:${v.chapter}:${v.index}:highlight";
397
391
  if (box.hasData(key)) {
398
392
  // box.remove(key);
399
393
  // print(box.read(key));
400
- return fromHexS(box.read(key));
394
+ final index = box.read<int>(key);
395
+ if (index == null) {
396
+ return null;
397
+ }
398
+ return darkMode ? darkHighlights[index] : lightHighlights[index];
401
399
  }
402
400
  return null;
403
401
  }
404
402
 
403
+ TextStyle getHighlightStyle(BuildContext context, Verse v) {
404
+ if (isVerseSelected(v)) {
405
+ return TextStyle(
406
+ backgroundColor: darkMode ? Colors.grey.shade800 : Colors.grey.shade200,
407
+ );
408
+ }
409
+ if (darkMode) {
410
+ return TextStyle(
411
+ color: getHighlight(v) ?? context.theme.colorScheme.onBackground,
412
+ );
413
+ }
414
+ return TextStyle(
415
+ backgroundColor: getHighlight(v) ?? context.theme.colorScheme.background,
416
+ );
417
+ }
418
+
405
- void setHighlight(BuildContext context, List<Verse> verses, Color c) {
419
+ void setHighlight(BuildContext context, List<Verse> verses, int index) {
406
420
  for (final v in verses) {
407
- box.write("${v.book}:${v.chapter}:${v.index}:highlight", toHexS(c));
421
+ box.write("${v.book}:${v.chapter}:${v.index}:highlight", index);
408
422
  }
409
423
  box.save();
410
424
  }
lib/theme.dart CHANGED
@@ -1,5 +1,19 @@
1
1
  import "package:flutter/material.dart";
2
2
 
3
+ const lightHighlights = [
4
+ Color(0xFFDAEFFE),
5
+ Color(0xFFFFFCB2),
6
+ Color(0xFFFFDDF3),
7
+ Color(0xFFE6FCC3),
8
+ ];
9
+
10
+ const darkHighlights = [
11
+ Color(0xFF69A9FC),
12
+ Color(0xFFFFEB66),
13
+ Color(0xFFFF66B3),
14
+ Color(0xFF48F334),
15
+ ];
16
+
3
17
  const lightColorScheme = ColorScheme.light(
4
18
  background: Colors.white,
5
19
  onBackground: Color(0xFF010101),
lib/widgets/highlight_button.dart CHANGED
@@ -1,15 +1,16 @@
1
1
  import "package:flutter/material.dart";
2
2
 
3
3
  class HighlightButton extends StatelessWidget {
4
+ final int index;
4
5
  final Color color;
5
- final Function(Color c) onColorSelected;
6
+ final Function(int) onHighlightSelected;
6
7
 
7
- const HighlightButton({super.key, required this.color, required this.onColorSelected});
8
+ const HighlightButton({super.key, required this.index, required this.color, required this.onHighlightSelected});
8
9
 
9
10
  @override
10
11
  Widget build(BuildContext context) {
11
12
  return InkWell(
12
- onTap: () => onColorSelected(color),
13
+ onTap: () => onHighlightSelected(index),
13
14
  child: Container(
14
15
  padding: const EdgeInsets.symmetric(horizontal: 10),
15
16
  decoration: BoxDecoration(
lib/widgets/highlight_sheet.dart CHANGED
@@ -1,4 +1,5 @@
1
1
  import "package:flutter/material.dart";
2
+ import "package:only_bible_app/theme.dart";
2
3
  import "package:only_bible_app/utils.dart";
3
4
  import "package:only_bible_app/widgets/highlight_button.dart";
4
5
 
@@ -10,36 +11,27 @@ class HighlightSheet extends StatelessWidget {
10
11
  final isDesktop = isWide(context);
11
12
  final bottom = isIOS() ? 20.0 : 0.0;
12
13
  final height = isIOS() ? 100.0 : 80.0;
13
- void onHighlight(Color c) {
14
+ void onHighlight(int index) {
14
15
  final verses = context.appEvent.selectedVerses;
15
- context.appEvent.setHighlight(context, verses, c);
16
+ context.appEvent.setHighlight(context, verses, index);
16
17
  context.appEvent.closeActions(context);
17
18
  }
19
+ // context.app.darkMode ? const Color(0xFF69A9FC) :
18
20
 
19
21
  return Container(
20
22
  height: height,
21
- color: Theme.of(context).colorScheme.background,
23
+ color: context.theme.colorScheme.background,
22
24
  padding: EdgeInsets.only(left: 20, right: 20, top: isDesktop ? 10 : 10, bottom: bottom),
23
25
  child: Row(
24
26
  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
25
- children: [
27
+ children: List.generate(
28
+ 4,
26
- HighlightButton(
29
+ (i) => HighlightButton(
30
+ index: i,
27
- color: const Color(0xFFDAEFFE),
31
+ color: context.app.darkMode ? darkHighlights[i] : lightHighlights[i],
28
- onColorSelected: onHighlight,
32
+ onHighlightSelected: onHighlight,
29
33
  ),
30
- HighlightButton(
31
- color: const Color(0xFFFFFBB1),
32
- onColorSelected: onHighlight,
33
- ),
34
+ ),
34
- HighlightButton(
35
- color: const Color(0xFFFFDEF3),
36
- onColorSelected: onHighlight,
37
- ),
38
- HighlightButton(
39
- color: const Color(0xFFE6FCC3),
40
- onColorSelected: onHighlight,
41
- ),
42
- ],
43
35
  ),
44
36
  );
45
37
  }
lib/widgets/verses_view.dart CHANGED
@@ -34,7 +34,7 @@ class VersesView extends StatelessWidget {
34
34
  // ),
35
35
  Align(
36
36
  alignment: Alignment.centerLeft,
37
- child: Text.rich(
37
+ child: Text.rich(
38
38
  // scrollPhysics: const BouncingScrollPhysics(),
39
39
  // contextMenuBuilder: null,
40
40
  textScaleFactor: app.textScaleFactor,
@@ -44,57 +44,51 @@ class VersesView extends StatelessWidget {
44
44
  TextSpan(
45
45
  style: app.fontBold
46
46
  ? textStyle.copyWith(
47
- fontWeight: FontWeight.w500,
47
+ fontWeight: FontWeight.w500,
48
- )
48
+ )
49
49
  : textStyle,
50
50
  // recognizer: TapAndPanGestureRecognizer()..onDragEnd = (e) => print("Hello"),
51
51
  children: chapter.verses
52
52
  .map(
53
53
  (v) => [
54
- WidgetSpan(
54
+ WidgetSpan(
55
- child: Transform.translate(
55
+ child: Transform.translate(
56
- offset: const Offset(0, -2),
56
+ offset: const Offset(0, -2),
57
- child: Text("${v.index + 1} ", style: Theme.of(context).textTheme.labelMedium),
57
+ child: Text("${v.index + 1} ", style: Theme.of(context).textTheme.labelMedium),
58
- ),
58
+ ),
59
- ),
59
+ ),
60
- if (app.hasNote(v))
60
+ if (app.hasNote(v))
61
- WidgetSpan(
61
+ WidgetSpan(
62
- child: Padding(
62
+ child: Padding(
63
- padding: const EdgeInsets.only(left: 3, right: 3),
63
+ padding: const EdgeInsets.only(left: 3, right: 3),
64
- child: GestureDetector(
64
+ child: GestureDetector(
65
- onTap: () {
65
+ onTap: () {
66
- app.showNoteField(context, v);
66
+ app.showNoteField(context, v);
67
- },
67
+ },
68
- child: const Icon(
68
+ child: const Icon(
69
- Icons.sticky_note_2_outlined,
69
+ Icons.sticky_note_2_outlined,
70
- size: 18,
70
+ size: 18,
71
- color: Colors.blue,
71
+ color: Colors.blue,
72
+ ),
73
+ ),
72
74
  ),
73
75
  ),
76
+ TextSpan(
77
+ text: "${v.text}\n",
78
+ style: context.app.getHighlightStyle(context, v),
79
+ recognizer: TapGestureRecognizer()
80
+ ..onTap = () {
81
+ context.appEvent.onVerseSelected(context, v);
82
+ // AppModel.ofEvent(context).showHighlightMenu(context, v, details.globalPosition);
83
+ },
74
84
  ),
85
+ const WidgetSpan(
86
+ child: Padding(
87
+ padding: EdgeInsets.only(top: 16, bottom: 16),
75
- ),
88
+ ),
76
- TextSpan(
89
+ ),
77
- text: "${v.text}\n",
78
- style: context.app.isVerseSelected(v)
79
- ? TextStyle(
90
+ ],
80
- backgroundColor: app.darkMode ? Colors.grey.shade800 : Colors.grey.shade200,
81
- )
91
+ )
82
- : TextStyle(
83
- backgroundColor: app.getHighlight(v) ?? context.theme.colorScheme.background,
84
- ),
85
- recognizer: TapGestureRecognizer()
86
- ..onTap = () {
87
- context.appEvent.onVerseSelected(context, v);
88
- // AppModel.ofEvent(context).showHighlightMenu(context, v, details.globalPosition);
89
- },
90
- ),
91
- const WidgetSpan(
92
- child: Padding(
93
- padding: EdgeInsets.only(top: 16, bottom: 16),
94
- ),
95
- ),
96
- ],
97
- )
98
92
  .expand((element) => element)
99
93
  .toList(),
100
94
  ),