-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
While learning flutter FutureBuilder , I was just creating a small POC for my understanding i.e fetching data from Rest Api (randomuser.me). In FutureBuilder default constructor we have three things from which initalData and future is optional.
const FutureBuilder({
Key? key,
this.future,
this.initialData,
required this.builder,
}) : assert(builder != null),
super(key: key);While making POC I forgot to supply both(future and initialData) but everything seems working fine. Untill I found it's not fetching data from web Api. I had spend around 15 minutes checking why my code is not fetching data from REST Api. Then I saw future is missing.
Flutter kept executing builder without even woorying about future which seems to bad UX for me as a developer. We should atleast warn or force developers to provide a future or initialData.
Eg.
FutureBuilder<String>(
builder:(ctx,snapshot)=>CircularProgressIndicator(),
);Everthing will work fine on above code, but will not work as expected since we haven't supplied necessary arguments.
Proposal
I think we should add one more validation(assert) in FutureBuilder<String>(). Which will force developers to supply atleast one or both from future and initialData.
Below is what I think can be done to improve UX of developing apps in flutter.
const FutureBuilder({
Key? key,
this.future,
this.initialData,
required this.builder,
}) : assert(builder != null),
assert(!(future == null && initialData == null),'Future and initialData cannot be null at same time'),
super(key: key);I have already started working on these. Just want to know if these can be accepted or we should move in any other direction.
These is my First Proposal or Feature Request. Pardon me for any mistakes.