Skip to content

Fix unable to load asset #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ibrahimmohamed2411
Copy link

This PR fixes this problem:
E/flutter (12221): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unable to load asset: "/data/user/0/com.example.app/app_flutter/logo.png".

@muhammadalkady
Copy link
Collaborator

This update does not fully resolve the original issue. The fallback to rootBundle.load(path) will still throw an exception if the specified asset does not exist. Additionally, it would be more efficient to replace File(path).existsSync() with await File(path).exists() to improve performance.

@ibrahimmohamed2411
Copy link
Author

Thank you for the feedback! I’ve updated the implementation based on your suggestions.
The issue I resolved occurs when attempting to pay with a card, navigating away from the payment page, and then returning to it, even though the asset is present.

@@ -248,7 +248,7 @@ class FlutterPaytabsBridge {

static Future<String> handleImagePath(String path) async {
var bytes;
if (File(path).existsSync()) {
if (await File(path).exists()) {
bytes = File(path).readAsBytesSync().buffer.asByteData();
} else {
bytes = await rootBundle.load(path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause the same exception to be thrown.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try the first commit as it is working as expected.

@ibrahimmohamed2411 ibrahimmohamed2411 force-pushed the fix_unable_to_load_asset branch 2 times, most recently from 526f705 to 7319dbe Compare November 23, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants