From fe01f66b617d7e0c38a90b76aff81be8b6d57b01 Mon Sep 17 00:00:00 2001 From: Rishi Raj Singh <49035175+rish07@users.noreply.github.com> Date: Thu, 25 Feb 2021 15:45:57 +0530 Subject: [PATCH] Add base64 support in image import (#41) --- app/android/settings_aar.gradle | 1 + app/pubspec.lock | 11 +++++++++-- lib/widgets/editor.dart | 15 ++++++++++++--- pubspec.lock | 9 ++++++++- pubspec.yaml | 2 ++ 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 app/android/settings_aar.gradle diff --git a/app/android/settings_aar.gradle b/app/android/settings_aar.gradle new file mode 100644 index 00000000..e7b4def4 --- /dev/null +++ b/app/android/settings_aar.gradle @@ -0,0 +1 @@ +include ':app' diff --git a/app/pubspec.lock b/app/pubspec.lock index 1b38ea1a..88e56154 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -145,7 +145,7 @@ packages: path: ".." relative: true source: path - version: "0.3.2" + version: "0.3.3" flutter_test: dependency: "direct dev" description: flutter @@ -321,7 +321,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -343,6 +343,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + string_validator: + dependency: transitive + description: + name: string_validator + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.4" term_glyph: dependency: transitive description: diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 0c4668d0..fe16ca67 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:io' as io; import 'dart:math' as math; @@ -19,6 +20,7 @@ import 'package:flutter_quill/widgets/image.dart'; import 'package:flutter_quill/widgets/raw_editor.dart'; import 'package:flutter_quill/widgets/responsive_widget.dart'; import 'package:flutter_quill/widgets/text_selection.dart'; +import 'package:string_validator/string_validator.dart'; import 'package:universal_html/prefer_universal/html.dart' as html; import 'package:url_launcher/url_launcher.dart'; @@ -407,9 +409,16 @@ class _QuillEditorSelectionGestureDetectorBuilder getEditor().context, MaterialPageRoute( builder: (context) => ImageTapWrapper( - imageProvider: imageUrl.startsWith('http') - ? NetworkImage(imageUrl) - : FileImage(io.File(blockEmbed.data))), + imageProvider: imageUrl.startsWith('http') + ? NetworkImage(imageUrl) + : (isBase64(imageUrl)) + ? Image.memory( + base64.decode(imageUrl), + ) + : FileImage( + io.File(blockEmbed.data), + ), + ), ), ); } diff --git a/pubspec.lock b/pubspec.lock index 664e3fc8..8cdc5c8f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -244,7 +244,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -266,6 +266,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + string_validator: + dependency: "direct main" + description: + name: string_validator + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.4" term_glyph: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9c6efdc4..e600b104 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,8 +22,10 @@ dependencies: photo_view: ^0.10.3 universal_html: ^1.2.1 file_picker: ^2.1.6 + string_validator: ^0.1.4 flutter_keyboard_visibility: ^4.0.4 + dev_dependencies: flutter_test: sdk: flutter