I want to modify data from a text asset (.txt file) with a function and display it in a Text()
widget. myFunction
Takes datatype String
as parameter and return datatype String
.
I've read the documentation. Loading Asset from Image, this didn't worked. I've also tried solution from Suragch's Answer.
This maybe is a case where I should use FutureBuilder
but I'm not able to understand how to make it work here (I'm new). I'm going to use another function to modify the data from file and then display.
This is one of the things I tried:
Widget build(BuildContext context) {
Future<String> aloadAsset(BuildContext context) async {
return await DefaultAssetBundle.of(context).loadString('assets/help.txt');
}
String helps = myFunction(await aloadAsset(context));
return Scaffold(
body: Text(helps)
);
}
When assigning value from await aloadAsset(context)
to String, I get these errors: Unexpected text 'await'.
& A value of type 'Future<String>' can't be assigned to a variable of type 'String'.