Resolve all lints and deprecation warnings

This commit is contained in:
2026-01-09 10:04:51 -06:00
parent 512577b092
commit a799e9cf59
56 changed files with 2819 additions and 3159 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:math';
import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart'; // For debugPrint
import 'package:hive_flutter/hive_flutter.dart'; // Import Hive
import '../services/bible_xml_parser.dart'; // Import the XML parser
@@ -39,12 +40,12 @@ class Scripture extends HiveObject {
reference: json['reference'],
reflection: json['reflection'],
applicablePhases: (json['applicablePhases'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ??
?.map((e) => e as String)
.toList() ??
[],
applicableContexts: (json['applicableContexts'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ??
?.map((e) => e as String)
.toList() ??
[],
);
}
@@ -54,6 +55,7 @@ class Scripture extends HiveObject {
verses[BibleTranslation.esv] ??
verses.values.first;
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
@@ -92,7 +94,9 @@ class Scripture extends HiveObject {
if (a.length != b.length) return false;
if (a.keys.length != b.keys.length) return false; // Added length check
for (final key in a.keys) {
if (!b.containsKey(key) || a[key] != b[key]) return false; // Added containsKey check
if (!b.containsKey(key) || a[key] != b[key]) {
return false; // Added containsKey check
}
}
return true;
}
@@ -103,26 +107,14 @@ class ScriptureDatabase {
static final ScriptureDatabase _instance = ScriptureDatabase._internal();
factory ScriptureDatabase({BibleXmlParser? bibleXmlParser}) {
_instance._bibleXmlParser = bibleXmlParser ?? BibleXmlParser();
return _instance;
}
ScriptureDatabase._internal();
late BibleXmlParser _bibleXmlParser;
late Box<Scripture> _scriptureBox;
// Mapping of BibleTranslation to its XML asset path
final Map<BibleTranslation, String> _translationFileMapping = {
BibleTranslation.esv: 'bible_xml/ESV.xml',
BibleTranslation.niv: 'bible_xml/NIV.xml',
BibleTranslation.nkjv: 'bible_xml/NKJV.xml',
BibleTranslation.nlt: 'bible_xml/NLT.xml',
BibleTranslation.nasb: 'bible_xml/NASB.xml',
BibleTranslation.kjv: 'bible_xml/KJV.xml',
BibleTranslation.msg: 'bible_xml/MSG.xml',
};
List<Scripture> _menstrualScriptures = [];
List<Scripture> _follicularScriptures = [];
@@ -137,17 +129,21 @@ class ScriptureDatabase {
Scripture(
reference: "Mark 10:45",
verses: {
BibleTranslation.esv: "For even the Son of Man came not to be served but to serve, and to give his life as a ransom for many.",
BibleTranslation.niv: "For even the Son of Man did not come to be served, but to serve, and to give his life as a ransom for many.",
BibleTranslation.esv:
"For even the Son of Man came not to be served but to serve, and to give his life as a ransom for many.",
BibleTranslation.niv:
"For even the Son of Man did not come to be served, but to serve, and to give his life as a ransom for many.",
},
reflection: "True leadership is servanthood. How can you serve your wife today?",
reflection:
"True leadership is servanthood. How can you serve your wife today?",
applicablePhases: ['husband'],
applicableContexts: ['leadership', 'servant'],
),
Scripture(
reference: "Philippians 2:3-4",
verses: {
BibleTranslation.esv: "Do nothing from selfish ambition or conceit, but in humility count others more significant than yourselves. Let each of you look not only to his own interests, but also to the interests of others.",
BibleTranslation.esv:
"Do nothing from selfish ambition or conceit, but in humility count others more significant than yourselves. Let each of you look not only to his own interests, but also to the interests of others.",
},
reflection: "Humility is the foundation of a happy marriage.",
applicablePhases: ['husband'],
@@ -156,8 +152,10 @@ class ScriptureDatabase {
Scripture(
reference: "Proverbs 29:18",
verses: {
BibleTranslation.esv: "Where there is no prophetic vision the people cast off restraint, but blessed is he who keeps the law.",
BibleTranslation.kjv: "Where there is no vision, the people perish: but he that keepeth the law, happy is he.",
BibleTranslation.esv:
"Where there is no prophetic vision the people cast off restraint, but blessed is he who keeps the law.",
BibleTranslation.kjv:
"Where there is no vision, the people perish: but he that keepeth the law, happy is he.",
},
reflection: "Lead your family with a clear, Godly vision.",
applicablePhases: ['husband'],
@@ -166,26 +164,32 @@ class ScriptureDatabase {
Scripture(
reference: "James 1:5",
verses: {
BibleTranslation.esv: "If any of you lacks wisdom, let him ask God, who gives generously to all without reproach, and it will be given him.",
BibleTranslation.esv:
"If any of you lacks wisdom, let him ask God, who gives generously to all without reproach, and it will be given him.",
},
reflection: "Seek God's wisdom in every decision you make for your family.",
reflection:
"Seek God's wisdom in every decision you make for your family.",
applicablePhases: ['husband'],
applicableContexts: ['wisdom', 'vision'],
),
Scripture(
reference: "1 Timothy 3:4-5",
verses: {
BibleTranslation.esv: "He must manage his own household well, with all dignity keeping his children submissive, for if someone does not know how to manage his own household, how will he care for God's church?",
BibleTranslation.esv:
"He must manage his own household well, with all dignity keeping his children submissive, for if someone does not know how to manage his own household, how will he care for God's church?",
},
reflection: "Your first ministry is your home. Manage it with love and dignity.",
reflection:
"Your first ministry is your home. Manage it with love and dignity.",
applicablePhases: ['husband'],
applicableContexts: ['leadership'],
),
Scripture(
reference: "Colossians 3:19",
verses: {
BibleTranslation.esv: "Husbands, love your wives, and do not be harsh with them.",
BibleTranslation.niv: "Husbands, love your wives and do not be harsh with them.",
BibleTranslation.esv:
"Husbands, love your wives, and do not be harsh with them.",
BibleTranslation.niv:
"Husbands, love your wives and do not be harsh with them.",
},
reflection: "Gentleness is a sign of strength, not weakness.",
applicablePhases: ['husband'],
@@ -206,9 +210,11 @@ class ScriptureDatabase {
_scriptureBox = await Hive.openBox<Scripture>('scriptures');
if (_scriptureBox.isEmpty) {
print('Hive box is empty. Importing scriptures from optimized JSON data...');
debugPrint(
'Hive box is empty. Importing scriptures from optimized JSON data...');
// Load the pre-processed JSON file which already contains all verse text
final String response = await rootBundle.loadString('assets/scriptures_optimized.json');
final String response =
await rootBundle.loadString('assets/scriptures_optimized.json');
final Map<String, dynamic> data = json.decode(response);
List<Scripture> importedScriptures = [];
@@ -218,28 +224,32 @@ class ScriptureDatabase {
for (var jsonEntry in list) {
final reference = jsonEntry['reference'];
final reflection = jsonEntry['reflection']; // Optional
final applicablePhases = (jsonEntry['applicablePhases'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ?? [];
final applicableContexts = (jsonEntry['applicableContexts'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ?? [];
final applicablePhases =
(jsonEntry['applicablePhases'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ??
[];
final applicableContexts =
(jsonEntry['applicableContexts'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ??
[];
// Map string keys (esv, niv) to BibleTranslation enum
Map<BibleTranslation, String> versesMap = {};
if (jsonEntry['verses'] != null) {
(jsonEntry['verses'] as Map<String, dynamic>).forEach((key, value) {
// Find enum by name (case-insensitive usually, but here keys are lowercase 'esv')
try {
final translation = BibleTranslation.values.firstWhere(
(e) => e.name.toLowerCase() == key.toLowerCase()
);
versesMap[translation] = value.toString();
} catch (e) {
print('Warning: Unknown translation key "$key" in optimized JSON');
}
// Find enum by name (case-insensitive usually, but here keys are lowercase 'esv')
try {
final translation = BibleTranslation.values.firstWhere(
(e) => e.name.toLowerCase() == key.toLowerCase());
versesMap[translation] = value.toString();
} catch (e) {
debugPrint(
'Warning: Unknown translation key "$key" in optimized JSON');
}
});
}
@@ -255,15 +265,26 @@ class ScriptureDatabase {
}
}
// Process all sections
if (data['menstrual'] != null) processList(data['menstrual'], 'menstrual');
if (data['follicular'] != null) processList(data['follicular'], 'follicular');
if (data['ovulation'] != null) processList(data['ovulation'], 'ovulation');
if (data['luteal'] != null) processList(data['luteal'], 'luteal');
if (data['husband'] != null) processList(data['husband'], 'husband');
if (data['womanhood'] != null) processList(data['womanhood'], 'womanhood');
if (data['menstrual'] != null) {
processList(data['menstrual'], 'menstrual');
}
if (data['follicular'] != null) {
processList(data['follicular'], 'follicular');
}
if (data['ovulation'] != null) {
processList(data['ovulation'], 'ovulation');
}
if (data['luteal'] != null) {
processList(data['luteal'], 'luteal');
}
if (data['husband'] != null) {
processList(data['husband'], 'husband');
}
if (data['womanhood'] != null) {
processList(data['womanhood'], 'womanhood');
}
if (data['contextual'] != null) {
final contextualMap = data['contextual'] as Map<String, dynamic>;
contextualMap.forEach((key, value) {
@@ -272,11 +293,14 @@ class ScriptureDatabase {
}
// Store all imported scriptures into Hive
for (var scripture in importedScriptures) {
await _scriptureBox.put(scripture.reference, scripture); // Using reference as key
}
final Map<String, Scripture> scripturesMap = {
for (var s in importedScriptures) s.reference: s
};
await _scriptureBox.putAll(scripturesMap);
debugPrint(
'Successfully imported ${importedScriptures.length} scriptures.');
} else {
print('Hive box is not empty. Loading scriptures from Hive...');
debugPrint('Hive box is not empty. Loading scriptures from Hive...');
}
// Populate internal lists from Hive box values
@@ -293,7 +317,8 @@ class ScriptureDatabase {
.where((s) => s.applicablePhases.contains('luteal'))
.toList();
_husbandScriptures = [
..._scriptureBox.values.where((s) => s.applicablePhases.contains('husband')),
..._scriptureBox.values
.where((s) => s.applicablePhases.contains('husband')),
..._hardcodedHusbandScriptures,
];
// Remove duplicates based on reference if any
@@ -308,10 +333,18 @@ class ScriptureDatabase {
.where((s) => s.applicableContexts.contains('womanhood'))
.toList();
_contextualScriptures = {
'anxiety': _scriptureBox.values.where((s) => s.applicableContexts.contains('anxiety')).toList(),
'pain': _scriptureBox.values.where((s) => s.applicableContexts.contains('pain')).toList(),
'fatigue': _scriptureBox.values.where((s) => s.applicableContexts.contains('fatigue')).toList(),
'joy': _scriptureBox.values.where((s) => s.applicableContexts.contains('joy')).toList(),
'anxiety': _scriptureBox.values
.where((s) => s.applicableContexts.contains('anxiety'))
.toList(),
'pain': _scriptureBox.values
.where((s) => s.applicableContexts.contains('pain'))
.toList(),
'fatigue': _scriptureBox.values
.where((s) => s.applicableContexts.contains('fatigue'))
.toList(),
'joy': _scriptureBox.values
.where((s) => s.applicableContexts.contains('joy'))
.toList(),
};
}
@@ -421,7 +454,6 @@ class ScriptureDatabase {
return scriptures[index];
}
// ... imports
// ... inside ScriptureDatabase class
@@ -518,10 +550,22 @@ class ScriptureDatabase {
...(_contextualScriptures['fatigue'] ?? []),
...(_contextualScriptures['joy'] ?? []),
];
if (scriptures.isEmpty) return Scripture(verses: {BibleTranslation.esv: "No scripture found."}, reference: "Unknown", applicablePhases: [], applicableContexts: []);
if (scriptures.isEmpty) {
return Scripture(
verses: {BibleTranslation.esv: "No scripture found."},
reference: "Unknown",
applicablePhases: [],
applicableContexts: []);
}
}
if (scriptures.isEmpty) return Scripture(verses: {BibleTranslation.esv: "No scripture found."}, reference: "Unknown", applicablePhases: [], applicableContexts: []);
if (scriptures.isEmpty) {
return Scripture(
verses: {BibleTranslation.esv: "No scripture found."},
reference: "Unknown",
applicablePhases: [],
applicableContexts: []);
}
return scriptures[Random().nextInt(scriptures.length)];
}
@@ -529,7 +573,11 @@ class ScriptureDatabase {
Scripture getHusbandScripture() {
final scriptures = _husbandScriptures;
if (scriptures.isEmpty) {
return Scripture(verses: {BibleTranslation.esv: "No husband scripture found."}, reference: "Unknown", applicablePhases: [], applicableContexts: []);
return Scripture(
verses: {BibleTranslation.esv: "No husband scripture found."},
reference: "Unknown",
applicablePhases: [],
applicableContexts: []);
}
return scriptures[Random().nextInt(scriptures.length)];
}