Skip to content

LiveActivityFileFromUrl.image Issue #140

@khawajmoiz406

Description

@khawajmoiz406

The image loads correctly when the URL points to a valid resource. However, if the URL returns a 404 or the image is otherwise inaccessible, the Live Activity fails to display it, and the code immediately enters the catch block. Since multiple images may be processed, it's difficult to identify which specific URL is causing the issue, as no detailed error context is provided.

Possible Solution:
If image loading fails, store null or an empty string in the entry instead of the file path. This would allow consumers of the data to handle missing or invalid images gracefully.

Affected Code:
File: live_activity_file.dart

Line 15:
Future<Uint8List?> loadFile();

Line 42:
@OverRide
Future<Uint8List?> loadFile() async {
try {
final ByteData byteData = await NetworkAssetBundle(Uri.parse(url)).load('');
return byteData.buffer.asUint8List();
} catch (e) {
return null;
}
}

Line 79:
@OverRide
Future<Uint8List?> loadFile() async {
try {
final byteData = await rootBundle.load(path);
return byteData.buffer.asUint8List();
} catch (e) {
return null;
}
}

Line 115:
@OverRide
Future<Uint8List?> loadFile() {
try {
return Future.value(data);
} catch (e) {
return Future.value(null);
}
}

File: app_groups_file_service.dart

Line 42:
final bytes = await value.loadFile();
if (bytes == null) {
data[key] = ''; // Set to empty string if image fails to load
continue;
}

Recommendation:
Instead of inserting the file path when bytes is null, set the entry to null or an empty string. This helps distinguish between valid and invalid image data and avoids attempting to use a path that doesn't point to a usable file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions