Resolve all lints and deprecation warnings
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:xml/xml.dart';
|
||||
import '../models/scripture.dart'; // Assuming Scripture model might need BibleTranslation
|
||||
|
||||
// Helper for background XML parsing
|
||||
XmlDocument parseXmlString(String xml) {
|
||||
@@ -14,18 +13,24 @@ class BibleXmlParser {
|
||||
static 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',
|
||||
'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',
|
||||
'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',
|
||||
'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',
|
||||
@@ -50,7 +55,6 @@ class BibleXmlParser {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Cache for parsed XML documents to avoid reloading/reparsing
|
||||
static final Map<String, XmlDocument> _xmlCache = {};
|
||||
|
||||
@@ -59,8 +63,8 @@ class BibleXmlParser {
|
||||
if (_xmlCache.containsKey(assetPath)) {
|
||||
return _xmlCache[assetPath]!;
|
||||
}
|
||||
|
||||
print('Loading and parsing XML asset: $assetPath'); // Debug log
|
||||
|
||||
debugPrint('Loading and parsing XML asset: $assetPath'); // Debug log
|
||||
final String xmlString = await rootBundle.loadString(assetPath);
|
||||
final document = await compute(parseXmlString, xmlString);
|
||||
_xmlCache[assetPath] = document;
|
||||
@@ -71,13 +75,11 @@ class BibleXmlParser {
|
||||
/// Supports two schemas:
|
||||
/// 1. <XMLBIBLE><BIBLEBOOK bname="..."><CHAPTER cnumber="..."><VERS vnumber="...">
|
||||
/// 2. <bible><b n="..."><c n="..."><v n="...">
|
||||
/// Extracts a specific verse from a parsed XML document.
|
||||
/// Supports two schemas:
|
||||
/// 1. <XMLBIBLE><BIBLEBOOK bname="..."><CHAPTER cnumber="..."><VERS vnumber="...">
|
||||
/// 2. <bible><b n="..."><c n="..."><v n="...">
|
||||
String? getVerseFromXml(XmlDocument document, String bookName, int chapterNum, int verseNum) {
|
||||
String? getVerseFromXml(
|
||||
XmlDocument document, String bookName, int chapterNum, int verseNum) {
|
||||
// Standardize book name for lookup
|
||||
String lookupBookName = _bookAbbreviations[bookName.toLowerCase()] ?? bookName;
|
||||
String lookupBookName =
|
||||
_bookAbbreviations[bookName.toLowerCase()] ?? bookName;
|
||||
|
||||
// Use root element to avoid full document search
|
||||
XmlElement root = document.rootElement;
|
||||
@@ -88,7 +90,7 @@ class BibleXmlParser {
|
||||
(element) {
|
||||
final nameAttr = element.getAttribute('bname');
|
||||
return nameAttr?.toLowerCase() == lookupBookName.toLowerCase() ||
|
||||
nameAttr?.toLowerCase() == bookName.toLowerCase();
|
||||
nameAttr?.toLowerCase() == bookName.toLowerCase();
|
||||
},
|
||||
orElse: () => XmlElement(XmlName('notfound')),
|
||||
);
|
||||
@@ -99,54 +101,54 @@ class BibleXmlParser {
|
||||
(element) {
|
||||
final nameAttr = element.getAttribute('n');
|
||||
return nameAttr?.toLowerCase() == lookupBookName.toLowerCase() ||
|
||||
nameAttr?.toLowerCase() == bookName.toLowerCase();
|
||||
nameAttr?.toLowerCase() == bookName.toLowerCase();
|
||||
},
|
||||
orElse: () => XmlElement(XmlName('notfound')),
|
||||
);
|
||||
}
|
||||
|
||||
if (bookElement.name.local == 'notfound') {
|
||||
// print('Book "$bookName" not found in XML.'); // Commented out to reduce log spam
|
||||
// debugPrint('Book "$bookName" not found in XML.'); // Commented out to reduce log spam
|
||||
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')),
|
||||
);
|
||||
(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')),
|
||||
);
|
||||
(element) => element.getAttribute('n') == chapterNum.toString(),
|
||||
orElse: () => XmlElement(XmlName('notfound')),
|
||||
);
|
||||
}
|
||||
|
||||
if (chapterElement.name.local == 'notfound') {
|
||||
// print('Chapter "$chapterNum" not found for book "$bookName".');
|
||||
// debugPrint('Chapter "$chapterNum" not found for book "$bookName".');
|
||||
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')),
|
||||
);
|
||||
(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')),
|
||||
);
|
||||
(element) => element.getAttribute('n') == verseNum.toString(),
|
||||
orElse: () => XmlElement(XmlName('notfound')),
|
||||
);
|
||||
}
|
||||
|
||||
if (verseElement.name.local == 'notfound') {
|
||||
// print('Verse "$verseNum" not found for Chapter "$chapterNum", book "$bookName".');
|
||||
// debugPrint('Verse "$verseNum" not found for Chapter "$chapterNum", book "$bookName".');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -158,7 +160,7 @@ class BibleXmlParser {
|
||||
Future<String?> getVerseFromAsset(String assetPath, String reference) async {
|
||||
final parsedRef = parseReference(reference);
|
||||
if (parsedRef == null) {
|
||||
print('Invalid reference format: $reference');
|
||||
debugPrint('Invalid reference format: $reference');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user