Flutter: How to preserve the file created through getApplicationDocumentsDirectory() on an iPhone? - iphone

I made an app for which I store images in a file (using getApplicationDocumentsDirectory()), everything works fine, except on the physical iPhone where I cannot access the data again if I quit the running app.
when I try to reopen the app I get this message error :
Reload already in progress, ignoring request
Restarted application in 1,654ms.
════════ Exception caught by image resource service ════════════════════════════
The following FileSystemException was thrown resolving an image codec:
Cannot open file, path = '/var/mobile/Containers/Data/Application/63108BB4-7170-44CF-8DF6-43885B77C05B/Documents/4TSqff2TFeUnxwQUJXymrZw23ir2.jpg' (OS Error: No such file or directory, errno = 2)
When the exception was thrown, this was the stack
#0 _File.open.<anonymous closure> (dart:io/file_impl.dart:356:9)
<asynchronous suspension>
#1 FileImage._loadAsync
<asynchronous suspension>
Path: /var/mobile/Containers/Data/Application/63108BB4-7170-44CF-8DF6-43885B77C05B/Documents/ImageName1.jpg
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════
Cannot open file, path = '/var/mobile/Containers/Data/Application/63108BB4-7170-44CF-8DF6-43885B77C05B/Documents/WgZMKUy95lOSV9jnlQOE6hbCStS2.jpg' (OS Error: No such file or directory, errno = 2)
════════════════════════════════════════════════════════════════════════════════
In android studio, I don't have this problem!

Related

Using Edge or Chrome to debug Flutter Applications

I'm trying to debug my app using edge.
And the first time it run...
It throws me exception saying...
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following ImageCodecException was thrown resolving an image codec:
Failed to load network image.
Image URL: https://i.ytimg.com/vi/eCx7dzYqb98/maxresdefault.jpg
Trying to load an image from another domain? Find answers at:
https://flutter.dev/docs/development/platform-integration/web-images
When the exception was thrown, this was the stack
Image provider: CachedNetworkImageProvider("https://i.ytimg.com/vi/eCx7dzYqb98/maxresdefault.jpg",
scale: 1)
Image key: CachedNetworkImageProvider("https://i.ytimg.com/vi/eCx7dzYqb98/maxresdefault.jpg",
scale: 1):
CachedNetworkImageProvider("https://i.ytimg.com/vi/eCx7dzYqb98/maxresdefault.jpg", scale: 1)
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: ImageCodecException: Failed to load network image.
Another exception was thrown: ImageCodecException: Failed to load network image.
But after I reloaded / restarted app...
Everything is working fine...
What is the reason for this?
When I debug on my mobile phone (I'm using it as emulator) everything is working fine...

Android studio flutter logs stacktrace doesn't show correct line number

Android studio for flutter doesn't show correct line number in console.
For e.g.
The following ArgumentError was thrown resolving an image codec:
Invalid argument(s): No host specified in URI file:///
When the exception was thrown, this was the stack:
#0 _HttpClient._openUrl (dart:_http/http_impl.dart:2667:9)
#1 _HttpClient.getUrl (dart:_http/http_impl.dart:2575:48)
#2 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:87:59)
#3 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:50:14)
And now have NetworkImage widget all over the code. How to figure out which line is causing this ?

The following ProviderNotFoundException was thrown building Consumer<ThemeProvider>(dirty)

Error: Could not find the correct Provider above this Consumer Widget
EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK
The following TestFailure object was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _TextFinder:<zero widgets with text "0" (ignoring offstage widgets)>
Which: means none were found but one was expected
When the exception was thrown, this was the stack:
#4 main.<anonymous closure> (file:///C:/flutter/MyProject/dumpit/test/widget_test.dart:19:5)
(elided one frame from package:stack_trace)
This was caught by the test expectation on the following line:
file:///C:/flutter/MyProject/dumpit/test/widget_test.dart line 19
The test description was:
Counter increments smoke test
There was default test case file present in test folder which was against my app model and hence threw an error. I got rid of it to solve my test run

Exception caught by image resource service The following assertion was thrown resolving an image codec:

════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: /data/user/0/com.Freedom.new_chat/cache/file_picker/-vimzzn.jpg
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:228
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync
package:flutter/…/painting/image_provider.dart:675
<asynchronous suspension>
Anyone can help me i can provide the codes
i would provide them now but i dont know which one have the error and thanks
now i get this one too
Image provider: AssetImage(bundle: null, name: "/data/user/0/com.Freedom.new_chat/cache/file_picker/Snapchat-1984491257.jpg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#534c4(), name: "/data/user/0/com.Freedom.new_chat/cache/file_picker/Snapchat-1984491257.jpg", scale: 1.0)
close your emulator and run this command
flutter clean
then run this command
flutter pub get
Run Your App

Flutter Unable to load asset: but dir doesnt exist

flutter throws these errors but the images he cant find does not exist!
the images that do exist are in the folder assets/images/ and have other (normal) names.
i imported them properly in pubspec.yaml
what can be the solution for this weird problem?
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/v.png
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:223:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:669:31)
#2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:652:14)
#3 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
#4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:360:22)
#5 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:503:80)
#6 ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:108:19)
#7 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:334:9)
#8 ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:464:26)
(elided 13 frames from dart:async)
Image provider: AssetImage(bundle: null, name: "assets/images/v.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#8dc86(), name: "assets/images/v.png",
scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/v.png
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:223:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:669:31)
#2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:652:14)
#3 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
...
Image provider: AssetImage(bundle: null, name: "assets/images/v.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#8dc86(), name: "assets/images/v.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: Unable to load asset: assets/images/e.png
════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/images/e.png
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: Unable to load asset: assets/images/h.png
════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/images/h.png
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: Unable to load asset: assets/images/i.png
════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/images/i.png
════════════════════════════════════════════════════════════════════════════════════════════════════
you can go to pubspec.yaml and give folder path there
assets:
- assets/images/
Don't need to give the name of image just give folder path then
run app again