I'm trying to make my app display the results of a HTTP request as a button. Here is the function that makes the request.
Future<String> client() async {
return await HttpRequest.getString('localhost:8000');
}
Here is the button I'd like to display it in.
ElevatedButton(
onPressed: () {},
child: Text('This is a Deck'),
),
I'd like to display the request in place of the string 'This is a Deck'. I've tried await client()
and client().toString()
but these did not work. Here is my full widget class if that helps.
class DeckButtons extends StatelessWidget {
DeckButtons({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ElevatedButton(
onPressed: () {},
child: Text('This is a Deck'),
),
IconButton(
icon: Icon(Icons.add),
onPressed: () {},
tooltip: 'Add a Card',
),
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
tooltip: 'See All Cards',
),
IconButton(
icon: Icon(Icons.delete),
onPressed: () {},
tooltip: 'Delete this Deck',
)
],
),
);
}
}
I'm brand new to Flutter and Asynchronous programming so my apologies if the answer to this question is obvious.
Edit: I've been told that my question is a duplicate of "What is a Future and how do I use it?". I don't think that my question is a duplicate because although some parts of the answer may apply to my situation, the question and the accepted answer are much too broad and cover a lot of additional information. Additionally, I still have not implemented a fix for my problem and I am unsure that the answer given in that post is of any help to me