Reputation: 12461
This is my code.
File('assets/i18n/en/strings.xml').readAsString().then((String contents) {
print(contents);
});
strings.xml is located at this path.
in pubspec.yaml
flutter:
assets:
- assets/i18n/en/strings.xml
However, I have this error.
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: FileSystemException: Cannot open file, path = 'assets/i18n/en/strings.xml' (OS Error: No such file or directory, errno = 2)
Is there any places I need to check to use File
class?
Upvotes: 1
Views: 1414
Reputation: 126964
You need to use AssetBundle
if you want to work with assets
in Flutter:
import 'package:flutter/services.dart' show rootBundle;
rootBundle.loadString('assets/i18n/en/strings.xml').then((String contents) {
print(contents);
});
If you want to learn more about it, you can follow the official article on assets in Flutter.
Upvotes: 1