I am trying to read the XML file in my flutter. But every time I try to read the file, it only throws an error.
This is where I read the xml file(My XML file is large).
convertXMLtoJSON() async {
File file = File('assets/xml_file/belovedskincare.xml');
Future<String> xml = file.readAsString();
}
And when I run this, it throws this error.
E/flutter (13956): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot open file, path = 'assets/xml_file/belovedskincare.xml' (OS Error: No such file or directory, errno = 2)
I have also tried some other functions like
file.readAsLines();
file.readAsStringSync();
But nothing changed.
this is my pubspec.yaml
The assets are working fine. You can see the file structure on the left side in the second image.
I have also tried the rootbundle
but its not working as well.
convertXMLtoJSON() async {
String file = await rootBundle.loadString('assets/xml_file/belovedskincare.xml');
print(file);
}
when I run this one, it shows this error.
E/flutter (13956): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value