Skip to content

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
Contributor

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.

if (await File(path).exists()) {
bytes = File(path).readAsBytesSync().buffer.asByteData();
} else {
bytes = await rootBundle.load(path);
Copy link
Contributor

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