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
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...
- [SOLVED] OAuth With Google & Flutter
Hi all, I'm trying to sign in with google and it all goes swimmingly until the call back. I get a new user created on the appwrite dashboard however the flutte...