How to save image in device and use it later?

2,756 views
Skip to first unread message

Niyazi Toros

unread,
Jul 27, 2018, 4:36:34 AM7/27/18
to Flutter Dev
Hi,

I have an image in my assets folder. I am using  image: "^2.0.4" plugin.
I load the my image from my assets folder, I add some string on top of it using image plugin and save it to disk.
This is work when using basic dart project and I am getting error to use in Flutter.

Error is:
E/flutter (19723): FileSystemException: Cannot open file, path = 'assets/images/CapitalBankDEKONT.jpg' (OS Error: No such file or directory, errno = 2)

In my assets folder I aldredy have the  - assets/images/CapitalBankDEKONT.jpg

dart project code:
import 'dart:io';
import 'package:image/image.dart';

void main() {
 
String mImagePath = 'images/CapitalBankDEKONT.jpg';


 
// load the receipt jpeg
 
Image _receiptImage = decodeImage(new File(mImagePath).readAsBytesSync());


flutter project code:

import 'dart:async';
import 'dart:io';

import 'package:image/image.dart';
Future<bool> makeReceiptImage() async {

 
String mImagePath = 'assets/images/CapitalBankDEKONT.jpg';

 
// load the receipt jpeg
 
Image _receiptImage =
 await decodeImage
(new File(mImagePath).readAsBytesSync());


Any help please?







bre...@tamu.edu

unread,
Jul 27, 2018, 9:29:07 AM7/27/18
to Flutter Dev
For images that are just sitting in your assets folder, you generally need to include it as an asset in the pubspec.yaml file. For this file (as an example), you would have

assets:
 
- assets/images/CapitalBankDEKONT.jpg

bre...@tamu.edu

unread,
Jul 27, 2018, 9:30:57 AM7/27/18
to Flutter Dev
And after adding it to your pubspec.yaml, make sure you run `packages get` to obtain the resource.

Niyazi Toros

unread,
Jul 27, 2018, 3:31:34 PM7/27/18
to Flutter Dev

 I already did that, twice.

assets:
 
- assets/images/CapitalBankDEKONT.jpg

and run  run `packages get` 

Fabio de Matos Quaresma Gonçalves

unread,
Jul 28, 2018, 7:05:56 PM7/28/18
to Niyazi Toros, Flutter Dev
You should use asset bundle object instead of new File. Follow the official docs. Mobile in general works much much different when it comes to relative folder and flutter adds even more differences. 

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niyazi Toros

unread,
Jul 31, 2018, 7:23:39 AM7/31/18
to Flutter Dev
Reply all
Reply to author
Forward
0 new messages