action method
- BuildContext context
override
Implementation
@override
Future<void> action(BuildContext context) async {
final NavigatorState navigatorState = Navigator.of(context);
if (!await ProductRefresher().checkIfLoggedIn(
context,
isLoggedInMandatory: isLoggedInMandatory,
)) {
return;
}
if (!context.mounted) {
return;
}
// best possibility: with the crop parameters
// TODO(monsieurtanuki): maybe we should keep the big image locally, in order to avoid the server call?
final ProductImage? productImage = _getBestProductImage();
if (productImage != null) {
final int? imageId = int.tryParse(productImage.imgid!);
if (imageId != null) {
await _openCropAgainPage(
context,
imageId,
productImage,
product.productType,
);
return;
}
}
// alternate option: use the transient file.
File? imageFile = _transientFile.getImage();
if (imageFile != null) {
await _openCropNewPage(navigatorState, imageFile);
return;
}
// but if not possible, get the best picture from the server.
final String? imageUrl = _imageData.getImageUrl(ImageSize.ORIGINAL);
if (context.mounted) {
imageFile = await downloadImageUrl(
context,
imageUrl,
DaoInt(context.read<LocalDatabase>()),
);
}
if (imageFile != null) {
await _openCropNewPage(navigatorState, imageFile);
return;
}
}