perf: Offload XML parsing to a background isolate using compute.
This commit is contained in:
@@ -1,7 +1,13 @@
|
|||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:xml/xml.dart';
|
import 'package:xml/xml.dart';
|
||||||
import '../models/scripture.dart'; // Assuming Scripture model might need BibleTranslation
|
import '../models/scripture.dart'; // Assuming Scripture model might need BibleTranslation
|
||||||
|
|
||||||
|
// Helper for background XML parsing
|
||||||
|
XmlDocument parseXmlString(String xml) {
|
||||||
|
return XmlDocument.parse(xml);
|
||||||
|
}
|
||||||
|
|
||||||
class BibleXmlParser {
|
class BibleXmlParser {
|
||||||
// Map of common Bible book names to their standard abbreviations or keys used in XML
|
// Map of common Bible book names to their standard abbreviations or keys used in XML
|
||||||
// This will help in matching references like "Matthew 11:28" to XML structure.
|
// This will help in matching references like "Matthew 11:28" to XML structure.
|
||||||
@@ -56,7 +62,7 @@ class BibleXmlParser {
|
|||||||
|
|
||||||
print('Loading and parsing XML asset: $assetPath'); // Debug log
|
print('Loading and parsing XML asset: $assetPath'); // Debug log
|
||||||
final String xmlString = await rootBundle.loadString(assetPath);
|
final String xmlString = await rootBundle.loadString(assetPath);
|
||||||
final document = XmlDocument.parse(xmlString);
|
final document = await compute(parseXmlString, xmlString);
|
||||||
_xmlCache[assetPath] = document;
|
_xmlCache[assetPath] = document;
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user