universal_io icon indicating copy to clipboard operation
universal_io copied to clipboard

The argument type 'File/*1*/' can't be assigned to the parameter type 'File/*2*/'.

Open grrrgpratik opened this issue 4 years ago • 8 comments

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,

grrrgpratik avatar Apr 05 '21 06:04 grrrgpratik

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';?

terrier989 avatar Apr 06 '21 16:04 terrier989

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 avatar Apr 10 '21 22:04 bcgreijnlautier

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;

myjinifuture avatar Aug 10 '21 09:08 myjinifuture

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())

amr-eniou-3r avatar Aug 10 '21 15:08 amr-eniou-3r

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 ?

am1tr0r avatar Oct 29 '21 14:10 am1tr0r

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';

jbryanh avatar Jan 04 '22 20:01 jbryanh

same problem , any news ?

Joseph-Nathan avatar Mar 25 '22 22:03 Joseph-Nathan

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

jbryanh avatar Mar 28 '22 13:03 jbryanh