universal_io
universal_io copied to clipboard
The argument type 'File/*1*/' can't be assigned to the parameter type 'File/*2*/'.
This issue is still not fixed in the latest version i.e 2.0.4
flutter run -d chrome
Launching lib\main.dart on Chrome in debug mode... lib/screens/myprofilescreen.dart:93:51: Error: The argument type 'File/1/' can't be assigned to the parameter type 'File/2/'.
- 'File/1/' is from 'package:universal_io/src/io/file.dart' ('/D:/flutter/.pub-cache/hosted/pub.dartlang.org/universal_io-2.0.4/lib/src/io/file.dart').
- 'File/2/' is from 'dart:io'. : new FileImage(_imageFile), ^ lib/screens/CreatePostScreen.dart:163:46: Error: The argument type 'File/1/' can't be assigned to the parameter type 'File/2/'.
- 'File/1/' is from 'package:universal_io/src/io/file.dart' ('/D:/flutter/.pub-cache/hosted/pub.dartlang.org/universal_io-2.0.4/lib/src/io/file.dart').
- 'File/2/' is from 'dart:io'. child: _image != null ? Image.file(_image) : null, ^ lib/screens/EditPostScreen.dart:155:46: Error: The argument type 'File/1/' can't be assigned to the parameter type 'File/2/'.
- 'File/1/' is from 'package:universal_io/src/io/file.dart' ('/D:/flutter/.pub-cache/hosted/pub.dartlang.org/universal_io-2.0.4/lib/src/io/file.dart').
- 'File/2/' is from 'dart:io'. child: _image != null ? Image.file(File(_image.path)) : null,
Hi! Package universal_html has a test case for File and it runs without problems in browsers. Does your application (or some dependency) accidentally contain directive import 'package:universal_io/src/io/file.dart';?
Here's a workaround you can use for now (and maybe this will help lead you to the root cause @terrier989):
Explicitly define the data type for your File as dynamic, then pass it to Image.file(). Here's a working example of how I'm using it:
dynamic file = File(source.path);
provider = FileImage(file);
There is a conflict between different file types. (eg. mine was html and dart) To resolve this import io package as
import 'dart: io' as i;
and declare file variable as
i.File imageFile;
I found the issue universal_io is working fine for me but Image.file is not universal so I used Image.memory( File(alternativeLocalImagePath).readAsBytesSync())
Here's a workaround you can use for now (and maybe this will help lead you to the root cause @terrier989):
Explicitly define the data type for your File as
dynamic, then pass it to Image.file(). Here's a working example of how I'm using it:
dynamic file = File(source.path);provider = FileImage(file);
@bcgreijnlautier not working for me . if I use dynamic type , I get this error "Expected a value of type 'File', but got one of type '_File'". have anyone found a proper solution ?
Perhaps this helps:
I am trying to convert my firebase project to a web app. The conflict is the universal file vs. the FirebaseStorage dart.io and the following is where I get stuck:
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage-10.0.5/lib/src/reference.dart:128:52: Error: The argument type 'File/*1*/' can't be assigned to the parameter type 'File/*2*/'.
- 'File/*1*/' is from 'package:universal_io/src/io/file.dart' ('../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/universal_io-2.0.4/lib/src/io/file.dart').
- 'File/*2*/' is from 'dart:io'.
return UploadTask._(storage, _delegate.putFile(file, metadata));
My import is import 'package:universal_io/io.dart';
same problem , any news ?
Assuming you are using XFile, there is a bug in fromData as documented here. That was the cause of my error, not related to universal_io