-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
- I create a future builder
- I write the contents of
builder - I forget to provider a
future - I run my app and the future builder never receives data
- I waste time debugging only to realize the simple mistake
In a toy example, step 5 is very fast. But if I've made a ton of changes at once in many places (eg a large refactor) step 5 can easily take several minutes. And if I'm using FutureBuilder heavily, this coding error can happen fairly often.
Proposal
Make future a required constructor argument.
In the (non-existent???) case where a developer intentionally didn't pass a variable (null or otherwise) for future, they can instead just write future: null.
In the typical case where a developer did intend to provide a variable, they will now get a compiler warning if they forget (and/or they'll never forget in the first place because their IDE auto-generates required arguments).
const FutureBuilder({
super.key,
this.initialData,
required this.future,
required this.builder,
}) : assert(builder != null);Also, by the exact same logic, StreamBuilder.stream should be a required argument too.