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,26 +1,76 @@
import 'dart:convert';
import 'dart:io';
import 'package:xml/xml.dart';
import 'package:flutter/foundation.dart';
// Copy of book abbreviations from BibleXmlParser
const Map<String, String> _bookAbbreviations = {
'genesis': 'Gen', 'exodus': 'Exod', 'leviticus': 'Lev', 'numbers': 'Num',
'deuteronomy': 'Deut', 'joshua': 'Josh', 'judges': 'Judg', 'ruth': 'Ruth',
'1 samuel': '1Sam', '2 samuel': '2Sam', '1 kings': '1Kgs', '2 kings': '2Kgs',
'1 chronicles': '1Chr', '2 chronicles': '2Chr', 'ezra': 'Ezra', 'nehemiah': 'Neh',
'esther': 'Esth', 'job': 'Job', 'psalm': 'Ps', 'proverbs': 'Prov',
'ecclesiastes': 'Eccl', 'song of solomon': 'Song', 'isaiah': 'Isa', 'jeremiah': 'Jer',
'lamentations': 'Lam', 'ezekiel': 'Ezek', 'daniel': 'Dan', 'hosea': 'Hos',
'joel': 'Joel', 'amos': 'Amos', 'obadiah': 'Obad', 'jonah': 'Jonah',
'micah': 'Mic', 'nahum': 'Nah', 'habakkuk': 'Hab', 'zephaniah': 'Zeph',
'haggai': 'Hag', 'zechariah': 'Zech', 'malachi': 'Mal',
'matthew': 'Matt', 'mark': 'Mark', 'luke': 'Luke', 'john': 'John',
'acts': 'Acts', 'romans': 'Rom', '1 corinthians': '1Cor', '2 corinthians': '2Cor',
'galatians': 'Gal', 'ephesians': 'Eph', 'philippians': 'Phil', 'colossians': 'Col',
'1 thessalonians': '1Thess', '2 thessalonians': '2Thess', '1 timothy': '1Tim',
'2 timothy': '2Tim', 'titus': 'Titus', 'philemon': 'Phlm', 'hebrews': 'Heb',
'james': 'Jas', '1 peter': '1Pet', '2 peter': '2Pet', '1 john': '1John',
'2 john': '2John', '3 john': '3John', 'jude': 'Jude', 'revelation': 'Rev',
'genesis': 'Gen',
'exodus': 'Exod',
'leviticus': 'Lev',
'numbers': 'Num',
'deuteronomy': 'Deut',
'joshua': 'Josh',
'judges': 'Judg',
'ruth': 'Ruth',
'1 samuel': '1Sam',
'2 samuel': '2Sam',
'1 kings': '1Kgs',
'2 kings': '2Kgs',
'1 chronicles': '1Chr',
'2 chronicles': '2Chr',
'ezra': 'Ezra',
'nehemiah': 'Neh',
'esther': 'Esth',
'job': 'Job',
'psalm': 'Ps',
'proverbs': 'Prov',
'ecclesiastes': 'Eccl',
'song of solomon': 'Song',
'isaiah': 'Isa',
'jeremiah': 'Jer',
'lamentations': 'Lam',
'ezekiel': 'Ezek',
'daniel': 'Dan',
'hosea': 'Hos',
'joel': 'Joel',
'amos': 'Amos',
'obadiah': 'Obad',
'jonah': 'Jonah',
'micah': 'Mic',
'nahum': 'Nah',
'habakkuk': 'Hab',
'zephaniah': 'Zeph',
'haggai': 'Hag',
'zechariah': 'Zech',
'malachi': 'Mal',
'matthew': 'Matt',
'mark': 'Mark',
'luke': 'Luke',
'john': 'John',
'acts': 'Acts',
'romans': 'Rom',
'1 corinthians': '1Cor',
'2 corinthians': '2Cor',
'galatians': 'Gal',
'ephesians': 'Eph',
'philippians': 'Phil',
'colossians': 'Col',
'1 thessalonians': '1Thess',
'2 thessalonians': '2Thess',
'1 timothy': '1Tim',
'2 timothy': '2Tim',
'titus': 'Titus',
'philemon': 'Phlm',
'hebrews': 'Heb',
'james': 'Jas',
'1 peter': '1Pet',
'2 peter': '2Pet',
'1 john': '1John',
'2 john': '2John',
'3 john': '3John',
'jude': 'Jude',
'revelation': 'Rev',
};
// Map of translations to filenames
@@ -35,12 +85,12 @@ final Map<String, String> _translationFiles = {
};
void main() async {
print('Starting asset optimization...');
debugPrint('Starting asset optimization...');
// 1. Load the base JSON
final File jsonFile = File('assets/scriptures.json');
if (!jsonFile.existsSync()) {
print('Error: assets/scriptures.json not found.');
debugPrint('Error: assets/scriptures.json not found.');
return;
}
final Map<String, dynamic> data = json.decode(jsonFile.readAsStringSync());
@@ -52,14 +102,14 @@ void main() async {
final path = entry.value;
final file = File(path);
if (file.existsSync()) {
print('Parsing $key from $path...');
debugPrint('Parsing $key from $path...');
try {
xmlDocs[key] = XmlDocument.parse(file.readAsStringSync());
} catch (e) {
print('Error parsing $path: $e');
debugPrint('Error parsing $path: $e');
}
} else {
print('Warning: $path not found.');
debugPrint('Warning: $path not found.');
}
}
@@ -90,7 +140,8 @@ void main() async {
outputFile.writeAsStringSync(json.encode(data)); // Minified
// outputFile.writeAsStringSync(const JsonEncoder.withIndent(' ').convert(data)); // Pretty print
print('Optimization complete. Wrote to assets/scriptures_optimized.json');
debugPrint(
'Optimization complete. Wrote to assets/scriptures_optimized.json');
}
Future<void> _processList(List list, Map<String, XmlDocument> xmlDocs) async {
@@ -101,31 +152,27 @@ Future<void> _processList(List list, Map<String, XmlDocument> xmlDocs) async {
// Parse reference
final parts = _parseReference(reference);
if (parts == null) {
print('Skipping invalid reference: $reference');
debugPrint('Skipping invalid reference: $reference');
continue;
}
// Look up for each translation
for (var entry in _translationFiles.entries) {
final transKey = entry.key; // esv, niv, etc.
// If already has text, skip (or overwrite? Let's overwrite to ensure consistency,
// but the original JSON had manual entries. The user wants to use the XMLs.
// If already has text, skip (or overwrite? Let's overwrite to ensure consistency,
// but the original JSON had manual entries. The user wants to use the XMLs.
// Let's only fill if missing or if we want to enforce XML source.)
// Strategy: Fill if we have XML data.
if (xmlDocs.containsKey(transKey)) {
final text = _getVerseFromXml(
xmlDocs[transKey]!,
parts['book']!,
int.parse(parts['chapter']!),
int.parse(parts['verse']!)
);
final text = _getVerseFromXml(xmlDocs[transKey]!, parts['book']!,
int.parse(parts['chapter']!), int.parse(parts['verse']!));
if (text != null) {
verses[transKey] = text;
} else {
print('Warning: Could not find $reference in $transKey');
debugPrint('Warning: Could not find $reference in $transKey');
}
}
}
@@ -140,92 +187,96 @@ Map<String, String>? _parseReference(String reference) {
String book = parts.sublist(0, parts.length - 1).join(' ').toLowerCase();
String chapterVerse = parts.last;
final cvParts = chapterVerse.split(':');
if (cvParts.length < 2) return null; // Only handles simple Chapter:Verse for now
if (cvParts.length < 2) {
return null; // Only handles simple Chapter:Verse for now
}
return {
'book': book,
'chapter': cvParts[0],
// Handle cases like "1-2" by just taking the first one?
// The current parser Logic only takes one verse number.
// If the reference is "Psalm 23:1-2", the XML parser expects a single integer.
// We should probably just parse the first verse or handle ranges?
// For this fix, let's just parse the start verse to prevent crashing on int.parse
'verse': cvParts[1].split('-')[0],
// Handle cases like "1-2" by just taking the first one?
// The current parser Logic only takes one verse number.
// If the reference is "Psalm 23:1-2", the XML parser expects a single integer.
// We should probably just parse the first verse or handle ranges?
// For this fix, let's just parse the start verse to prevent crashing on int.parse
'verse': cvParts[1].split('-')[0],
};
}
String? _getVerseFromXml(XmlDocument document, String bookName, int chapterNum, int verseNum) {
// Standardize book name for lookup
String lookupBookName = _bookAbbreviations[bookName.toLowerCase()] ?? bookName;
String? _getVerseFromXml(
XmlDocument document, String bookName, int chapterNum, int verseNum) {
// Standardize book name for lookup
String lookupBookName =
_bookAbbreviations[bookName.toLowerCase()] ?? bookName;
// Use root element to avoid full document search
XmlElement root = document.rootElement;
// Use root element to avoid full document search
XmlElement root = document.rootElement;
// -- Find Book --
// Try Schema 1: Direct child of root
var bookElement = root.findElements('BIBLEBOOK').firstWhere(
// -- Find Book --
// Try Schema 1: Direct child of root
var bookElement = root.findElements('BIBLEBOOK').firstWhere(
(element) {
final nameAttr = element.getAttribute('bname');
return nameAttr?.toLowerCase() == lookupBookName.toLowerCase() ||
nameAttr?.toLowerCase() == bookName.toLowerCase();
},
orElse: () => XmlElement(XmlName('notfound')),
);
// Try Schema 2 if not found
if (bookElement.name.local == 'notfound') {
bookElement = root.findElements('b').firstWhere(
(element) {
final nameAttr = element.getAttribute('bname');
final nameAttr = element.getAttribute('n');
return nameAttr?.toLowerCase() == lookupBookName.toLowerCase() ||
nameAttr?.toLowerCase() == bookName.toLowerCase();
nameAttr?.toLowerCase() == bookName.toLowerCase();
},
orElse: () => XmlElement(XmlName('notfound')),
);
// Try Schema 2 if not found
if (bookElement.name.local == 'notfound') {
bookElement = root.findElements('b').firstWhere(
(element) {
final nameAttr = element.getAttribute('n');
return nameAttr?.toLowerCase() == lookupBookName.toLowerCase() ||
nameAttr?.toLowerCase() == bookName.toLowerCase();
},
orElse: () => XmlElement(XmlName('notfound')),
);
}
if (bookElement.name.local == 'notfound') {
return null;
}
// -- Find Chapter --
// Try Schema 1: Direct child of book
var chapterElement = bookElement.findElements('CHAPTER').firstWhere(
(element) => element.getAttribute('cnumber') == chapterNum.toString(),
orElse: () => XmlElement(XmlName('notfound')),
);
// Try Schema 2 if not found
if (chapterElement.name.local == 'notfound') {
chapterElement = bookElement.findElements('c').firstWhere(
(element) => element.getAttribute('n') == chapterNum.toString(),
orElse: () => XmlElement(XmlName('notfound')),
);
}
if (chapterElement.name.local == 'notfound') {
return null;
}
// -- Find Verse --
// Try Schema 1: Direct child of chapter
var verseElement = chapterElement.findElements('VERS').firstWhere(
(element) => element.getAttribute('vnumber') == verseNum.toString(),
orElse: () => XmlElement(XmlName('notfound')),
);
// Try Schema 2 if not found
if (verseElement.name.local == 'notfound') {
verseElement = chapterElement.findElements('v').firstWhere(
(element) => element.getAttribute('n') == verseNum.toString(),
orElse: () => XmlElement(XmlName('notfound')),
);
}
if (verseElement.name.local == 'notfound') {
return null;
}
// Extract the text content of the verse
return verseElement.innerText.trim();
}
if (bookElement.name.local == 'notfound') {
return null;
}
// -- Find Chapter --
// Try Schema 1: Direct child of book
var chapterElement = bookElement.findElements('CHAPTER').firstWhere(
(element) => element.getAttribute('cnumber') == chapterNum.toString(),
orElse: () => XmlElement(XmlName('notfound')),
);
// Try Schema 2 if not found
if (chapterElement.name.local == 'notfound') {
chapterElement = bookElement.findElements('c').firstWhere(
(element) => element.getAttribute('n') == chapterNum.toString(),
orElse: () => XmlElement(XmlName('notfound')),
);
}
if (chapterElement.name.local == 'notfound') {
return null;
}
// -- Find Verse --
// Try Schema 1: Direct child of chapter
var verseElement = chapterElement.findElements('VERS').firstWhere(
(element) => element.getAttribute('vnumber') == verseNum.toString(),
orElse: () => XmlElement(XmlName('notfound')),
);
// Try Schema 2 if not found
if (verseElement.name.local == 'notfound') {
verseElement = chapterElement.findElements('v').firstWhere(
(element) => element.getAttribute('n') == verseNum.toString(),
orElse: () => XmlElement(XmlName('notfound')),
);
}
if (verseElement.name.local == 'notfound') {
return null;
}
// Extract the text content of the verse
return verseElement.innerText.trim();
}