Dart error: The argument type 'Future<File>' can't be assigned to the parameter type 'File'
The argument type 'Future<File>' can't be assigned to the parameter type 'File'.Short answer
A Future<File> is a promise of a file, not the file itself. Wherever a plain File is needed, wait for the future first: put await in an async function, or let a FutureBuilder hand you the value when it completes. Creating the future inside build causes a second problem, so start it in initState.
Fix it fast
1Find out which cause you have
Find the call that produces the future and read its declared return type in the analyzer message or by hovering. Every function marked async returns a Future, so a call to it gives a Future even if the body returns a plain File.
dart analyze lib/2Match what you see, then jump to its fix
- 1
The error sits on a line that calls your own helper, and the helper is declared Future<File>The call is missing await inside an async functionFix - 2
The call sits in build(), a constructor argument or a field initializer, where await is not allowedYou are in a place that cannot be async, such as a widget's build methodFix
- 1
What does the error look like?
The argument type 'Future<File>' can't be assigned to the parameter type 'File'.
Cause 1 of 2
The call is missing await inside an async function
1Check
Dart's guide says await unwraps a future and works only inside an async function. Without it you hold an uncompleted future, which prints as Instance of '_Future<...>'.
grep -n 'Future<File>' -r lib/2Fix
Mark the calling function async and put await before the call. Do not change the helper's return type to File: an async function always returns a Future.
Future<void> save() async {
final File file = await createLocalFile('notes.txt');
await upload(file);
}3Verify
Analysis is clean and the file value is a real File at that line.
dart analyze lib/Confirmed by dart.dev
Cause 2 of 2
You are in a place that cannot be async, such as a widget's build method
1Check
build must return a widget at once, so it cannot wait. Flutter's FutureBuilder is meant for this: it shows its state until the future completes, then gives you snapshot.data.
grep -n 'FutureBuilder' -r lib/2Fix
Start the future once in initState, keep it in a field, and read the finished file in the builder. The FutureBuilder docs warn that the future must not be created during build, because each rebuild would start the work again.
late final Future<File> _fileFuture;
@override
void initState() {
super.initState();
_fileFuture = createLocalFile('notes.txt');
}
@override
Widget build(BuildContext context) {
return FutureBuilder<File>(
future: _fileFuture,
builder: (context, snapshot) {
if (!snapshot.hasData) return const CircularProgressIndicator();
return Text(snapshot.data!.path);
},
);
}3Verify
The screen shows a progress indicator first, then the data, and the error is gone.
flutter analyzeConfirmed by api.flutter.dev
How do I stop it coming back?
- Name async helpers so the reader expects a future, for example loadFile, and keep Future in their return type.
- Turn on the discarded_futures lint in analysis_options.yaml, as Dart's guide suggests.
- Create futures in initState or a controller, never inside build.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix