From ac933e07fb41ed72572476c152ed0566aadbe292 Mon Sep 17 00:00:00 2001 From: X Code Date: Sun, 6 Feb 2022 09:18:59 -0800 Subject: [PATCH] Upgrade to 3.9.9 --- CHANGELOG.md | 3 ++ .../widgets/embeds/default_embed_builder.dart | 21 +------------- lib/src/widgets/embeds/image.dart | 29 +++++++++++++++++++ pubspec.yaml | 2 +- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d5ce232..8602f221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# [3.9.9] +* iOS: Save image whose filename does not end with image file extension. + # [3.9.8] * Added Urdu translation. diff --git a/lib/src/widgets/embeds/default_embed_builder.dart b/lib/src/widgets/embeds/default_embed_builder.dart index 26ffd7be..eb46585e 100644 --- a/lib/src/widgets/embeds/default_embed_builder.dart +++ b/lib/src/widgets/embeds/default_embed_builder.dart @@ -162,26 +162,7 @@ Widget _menuOptionsForReadonlyImage( color: Colors.greenAccent, text: 'Save'.i18n, onPressed: () { - const List imageFormats = [ - '.jpeg', - '.png', - '.jpg', - '.gif', - '.webp', - '.tif', - '.heic' - ]; - - List endsWithFormats = imageFormats.where((imageFormat) => imageUrl.toLowerCase().endsWith(imageFormat)).toList(); - if (endsWithFormats.length == 0) { - for(int i = 0; i < imageFormats.length; i++) { - if (imageUrl.toLowerCase().contains(imageFormats[i])) { - imageUrl += imageFormats[i]; - break; - } - } - } - + imageUrl = appendFileExtensionToImageUrl(imageUrl); GallerySaver.saveImage(imageUrl).then((_) { ScaffoldMessenger.of(context) .showSnackBar(SnackBar(content: Text('Saved'.i18n))); diff --git a/lib/src/widgets/embeds/image.dart b/lib/src/widgets/embeds/image.dart index c7e9f9e3..6bbedd18 100644 --- a/lib/src/widgets/embeds/image.dart +++ b/lib/src/widgets/embeds/image.dart @@ -12,6 +12,16 @@ import '../../models/documents/nodes/leaf.dart'; import '../../models/documents/style.dart'; import '../controller.dart'; +const List imageFileExtensions = [ + '.jpeg', + '.png', + '.jpg', + '.gif', + '.webp', + '.tif', + '.heic' +]; + bool isImageBase64(String imageUrl) { return !imageUrl.startsWith('http') && isBase64(imageUrl); } @@ -64,6 +74,25 @@ String standardizeImageUrl(String url) { return url; } +/// This is a bug of Gallery Saver Package. +/// It can not save image that's filename does not end with it's file extension +/// like below. +// "https://firebasestorage.googleapis.com/v0/b/eventat-4ba96.appspot.com/o/2019-Metrology-Events.jpg?alt=media&token=bfc47032-5173-4b3f-86bb-9659f46b362a" +/// If imageUrl does not end with it's file extension, +/// file extension is added to image url for saving. +String appendFileExtensionToImageUrl(String url) { + final endsWithImageFileExtension = imageFileExtensions + .firstWhere((s) => url.toLowerCase().endsWith(s), orElse: () => ''); + if (endsWithImageFileExtension.isNotEmpty) { + return url; + } + + final imageFileExtension = imageFileExtensions + .firstWhere((s) => url.toLowerCase().contains(s), orElse: () => ''); + + return url + imageFileExtension; +} + class ImageTapWrapper extends StatelessWidget { const ImageTapWrapper({ required this.imageUrl, diff --git a/pubspec.yaml b/pubspec.yaml index 5526ddd0..6823b7f7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: A rich text editor supporting mobile and web (Demo App @ bulletjournal.us) -version: 3.9.8 +version: 3.9.9 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html repository: https://github.com/singerdmx/flutter-quill