I'm trying to handle the error if the file with the user id doesn't exist Appwrite store, then display the local image.
my code widget:
FutureBuilder<Uint8List>(
future: storage.getFilePreview(
bucketId: bucketId,
fileId: docID,
),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data != null) {
final imageBytes = snapshot.data!;
return CircleAvatar(
radius: 70,
backgroundColor: Colors.grey[200],
backgroundImage: MemoryImage(imageBytes),
);
} else if (snapshot.hasError) {
print(
'error get preview: ${snapshot.error}');
}
return CircularProgressIndicator();
},
),
if the file the user has exists in the appwrite repository, then the image displays fine!
but if the user's files don't exist in the repository, then I get an error, and that makes sense.
I need to handle the error correctly if I get an error:
AppwriteException (AppwriteException: storage_file_not_found, The requested file could not be found. (404))
In this case, display the local image.
how do i do this?
Isn't your hasError block executing?
I still get an error and my application crashes. I tried uninstalling the application from the emulator, did flutter clean, flutter run. Didn't help
future: storage.getFilePreview(
bucketId: bucketId,
fileId: docID,
),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data != null) {
final imageBytes = snapshot.data!;
return CircleAvatar(
radius: 70,
backgroundColor: Colors.grey[200],
backgroundImage: MemoryImage(imageBytes),
);
} else if (snapshot.hasError) {
return CircleAvatar(
radius: 70,
backgroundColor: Colors.grey[200],
backgroundImage: AssetImage(
'assets/android12splash.png'),
);
}
return CircularProgressIndicator();
},
),```
This is fine. This is because of your debugger
Thank you so much!
I didn't know!
[SOLVED] Problem with file error handling in Flutter x Appwrite
Recommended threads
- Realtime: Listener not triggered on upda...
I self host appwrite 1.8.1. The genereal functionallity works fine. But my realtime subscription isn't updating. I see "Received heartbeat response from realtim...
- Realtime for files() works almost well, ...
I have been trying to make use of realtime, today (14.03.26) I have pulled all the latest versions of docker images, and sdk available. Whats working: - Conn...
- Impossible to get USER after createEmail...
Am using provider to deal with functions linked to appwrite. Here is my login. Future<String?> login(String email, String password) async { try { aw...