flutter / dart error: The argument type 'Future<File>' can't be assigned to the parameter type 'File'
ref.put
asks for a File
as parameter. What you are passing is a Future<File>
.
You need to wait for the result of that future to make your call.
You can change your code to
final StorageUploadTask uploadTask = ref.put(await _imageFile);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
Or change _imageFile
to File
instead of Future<File>
For those who are still looking for answers, as it seems there are different reasons for the same error. In my case, it was the different import statement for a file which I was passing as parameters to a different function. It should be same file(import) in case of declaration and definition.
for example, don't use like this in dart:
import 'GitRepoResponse.dart';
import 'GitRowItem.dart';
and then in some another class
import 'package:git_repo_flutter/GitRepoResponse.dart';
import 'package:git_repo_flutter/GitRowItem.dart';
because
In Dart, two libraries are the same if, and only if, they are imported using the same URI. If two different URIs are used, even if they resolve to the same file, they will be considered to be two different libraries and the types within the file will occur twice
Read more here
From the plugin README.md
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_image = image;
});
}
ImagePicker.pickImage()
returns a Future
. You can use async
/await
like shown in the code above the get the value from the Future
.