Hi I am trying to access a asset in my dart function but I don't know how to set the path properly.
Would it be possible to share the code to see how your imports and folder structure are doing?
I have some functions in dart, what I needed to do was import them from the dart project name:
pubspec.yaml:
name: my_function
in the archives:
import 'package:my_function/modules/model/any_files.dart’;
For example rootBundle.load("lib/example.txt'')
import 'dart:async' show Future; import 'package:flutter/services.dart' show rootBundle;
Future<String> loadAsset() async { return await rootBundle.loadString('assets/my_text.txt'); }
Or if you have the BuildContext (inside a widget) you can use DefaultAssetBundle. This is recommended because it allows switching asset bundles at runtime, which is useful for multilingual assets.
Future<String> loadAsset(BuildContext context) async { return await DefaultAssetBundle.of(context).loadString('assets/my_text.txt'); }
Recommended threads
- Selfhost - Starting Docker containers fa...
I am stuck at installing appwrite. Specifically, the containers dont want to start up. The images are downloaded and ready. Dockhand is reporting containers st...
- It says domain already used but I have d...
I accidentally deleted the project in which I used my domain originally (orexia.app) from name.com. Now I am trying to add it to a different project and it says...
- Is this normal in the self host custom d...
when i try to add custom domain to the project did not see this in 1.8.0 ok when pressed the retry it says "DNS verification failed with resolver 8.8.8.8. Domai...