PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

[FIXED] How to display an image from local storage

 May 06, 2022     dart, flutter, image     No comments   

Issue

I took a picture with the camera and I got its path

/data/user/0/com.example.tarea_8/cache/CAP8057460019038129642.jpg

I tried to display it like this

var imagePath = '/data/user/0/com.example.tarea_8/cache/CAP8057460019038129642.jpg';
Image.file(File(imagePath));

But I got this error

The argument type 'File (where File is defined in C:\flutter\bin\cache\pkg\sky_engine\lib\html\html_dart2js.dart)' can't be assigned to the parameter type 'File (where File is defined in C:\flutter\bin\cache\pkg\sky_engine\lib\io\file.dart)'. (Documentation) 

File is defined in C:\flutter\bin\cache\pkg\sky_engine\lib\html\html_dart2js.dart (html_dart2js.dart:144).

File is defined in C:\flutter\bin\cache\pkg\sky_engine\lib\io\file.dart (file.dart:144).

2 positional argument(s) expected, but 1 found. (Documentation) 

dart:html (new) File File(   List  fileBits,   String fileName, [   Map ? options, ]

I saw that someone had the same problem 3 year ago here. I followed the solution steps to the letter but it didn't work for me.

I am using Android Studio and the version of the installed plugins are Dart 211.7808 & Flutter 65.2.2


Solution

Check your imports this Error say's that File id defined in both dart:html and dart:io.

solution 1: if you are not using functionality of dart:html remove it from imports and your code will be running. (i am saying this first solution because dart:html only runs on flutter web and dart:io does not work on web).

solution 2: you have to import any of one library as named import and then use. (import alies/named imports)

import 'dart:async';
import 'my_library.dart' as myLib;

void main() {
  Stream stream = new Stream.fromIterable([1, 2]); // from async
  myLib.Stream myCustomStream = new myLib.Stream(); // from your library
}


Answered By - Ruchit
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing