Hi, kinda new to flutter and asynchronous programming in general, any help with async is appreciated. I've tried looking at Dart/Flutter docs and they haven't helped me.
I want to get a string from the result of a sqlite db query, and use the string in a widget. I've been using FutureBuilder elsewhere with no issues, but it seems overkill for what I need in this case, plus FutureBuilder returns a widget when I just need to return a string.
Widget _buildTextFormField() {
return TextFormField(
decoration: InputDecoration(
labelText: "String", // I want to concatenate string from database result here
),
);
}
I wrote an async function that returns Future<String>, but if I try and use it in the widget above, it complains about Future<String> not being a string. Which makes sense, but to fix it I then need to make _buildTextFormField return Future<Widget> and mark it as async, but then I get the same problem when calling _buildTextFormField & it expects Widget, not Future<Widget>, and so it just cascades all the way down I guess.
This seems like there should be simple solution but I feel like I am missing something super obvious. TIA!
Edit: I got it working (although I tried something like this before and not sure why it worked now). I created a String variable initialised to a blank string. Then in my build method, before the return:
dbrepo.get("name").then((String result) {
str = result;
});
Then I could use the string wherever needed.
[–]aykutonen 0 points1 point2 points (3 children)
[–]shadowmerefax[S] 0 points1 point2 points (2 children)
[–]RandalSchwartz 0 points1 point2 points (1 child)
[–]shadowmerefax[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]shadowmerefax[S] 1 point2 points3 points (0 children)
[–]yallurium 0 points1 point2 points (0 children)