last day (15 days later) » 

12:02 PM
0
Q: Flutter - Return a future widget from a widget

Abhinav PrabhakarI was following this tutorial while making a todo app in flutter: https://medium.com/flutter-community/simple-to-do-list-app-in-flutter-26abc50db741 I had the same problem yesterday too on a different project on a bottom model sheet, any solution? Or at least can someone explain what this is? ED...

 
Please avoid uploading code as picture. I don't see what are you trying to return in the build function.
 
Which is the reason why I also provided the link to the tutorial I am following. Thank you, though.
 
My guess is that this guide was written before null-safety. Change declaration of _displayDialog from Future<AlertDialog> to Future<AlertDialog?>, and handle the case when it returns null. FlatButton is also deprecated.
 
Oh yeah! thanks a ton. Didn't even think of null safety being the issue : )
@Peter Koltai I need a small help: When I use the function in my button onPressed: () => _displayDialog(context),, I get invalid constant value as the error. Any solution?
 
Please add the code that you are having trouble with.
 
12:03 PM
I am using that function here: floatingActionButton: const FloatingActionButton(
onPressed: () => _displayDialog(context),
tooltip: 'Add Item',
child: Icon(Icons.add),
),
 
Do you know what const means?
 
And I get the error: Invalid constant value. (dart(invalid_constant))
Yes
 
And is _displayDialog(context) a const value that can be evaluated during compile?
 
No
Oh I get it, it's a future that's why
But is there a solution?
 
Yes, there is a solution. Simply remove const from before FloatingActionButton, and add it only before Icon(Icons.add). I would recommend learning the basics of Dart language because you will have a lot of problems with Flutter.
 
12:10 PM
Yeah man.. It's not that I am a beginner, but rather because the last time I used flutter was a few years ago lol.
Thanks!
That solved it!
 
And it has nothing to do with the future. It would give you the same error with any function because these can be evaluated only at runtime therefore can't be const.
 
lol, I got it wrong then
I forgot almost everything
 

last day (15 days later) »