-
-
Notifications
You must be signed in to change notification settings - Fork 17
Best Practice
Midori edited this page Feb 4, 2024
·
34 revisions
Use try-catch
in production code. Gal
throws a GalException
if an error occurs
while saving media. You can get a message for each type with GalException.type.message
.
try {
await Gal.putImage($path);
} on GalException catch (e) {
log(e.type.message);
}
enum GalExceptionType {
accessDenied,
notEnoughSpace,
notSupportedFormat,
unexpected;
String get message => switch (this) {
accessDenied => 'You do not have permission to access the gallery app.',
notEnoughSpace => 'Not enough space for storage.',
notSupportedFormat => 'Unsupported file formats.',
unexpected => 'An unexpected error has occurred.',
};
}
If there is no particular reason, you should use putImage
.
The primary advantage of putImage
is file extension is to be taken over from the filename. Conversely, with putImageBytes
, this is determined automatically and may result in unintended behavior with minor devices and extensions.
Feature | putImage | putImageBytes |
---|---|---|
File Type | Same as input | Auto detect |