I have been trying to add the return statement of a Future in a Widget. Here is my Future code:
Future<Widget> readName() async {
try {
final file = await _localNames;
// Read the file
String contents = await file.readAsString();
return Text('Assignment' + contents);
} catch (e) {
// If encountering an error, return 0
return Text('Error');
}
}
This is my widget:
Widget build(BuildContext ctxt) {
return MaterialApp(
home: Scaffold(
appBar: new AppBar(
title: new Text("My assignments"),
),
body: Container(
margin: const EdgeInsets.only(top: 10.0),
child: Align(
alignment: Alignment(0, -0.9),
child: Column(
children: <Widget>[
// Need Text Here
],
),
),
),
),
);
}
How do you solve this? I have been trying to find out the solution for a day. Thanks for your time!