diff --git a/CHANGELOG.md b/CHANGELOG.md index f580708a..00883b32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.5.0+1] - 2021-03-10 +* Fixed getText() returning null on mobile for any device + ## [1.5.0] - 2021-03-01 * Nullsafety preview * Added Flutter's Hybrid Composition to the HTML Editor. This significantly improves the keyboard experience on Android. diff --git a/example/pubspec.lock b/example/pubspec.lock index 9db2df3c..3e652ec0 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -43,13 +43,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.0" cupertino_icons: dependency: "direct main" description: @@ -57,20 +50,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" - device_info: - dependency: transitive - description: - name: device_info - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" - device_info_platform_interface: - dependency: transitive - description: - name: device_info_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" fake_async: dependency: transitive description: @@ -89,7 +68,7 @@ packages: name: flutter_inappwebview url: "https://pub.dartlang.org" source: hosted - version: "5.0.4-nullsafety.1" + version: "5.1.0+4" flutter_test: dependency: "direct dev" description: flutter @@ -101,14 +80,7 @@ packages: path: ".." relative: true source: path - version: "1.4.0" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.0" + version: "1.5.0+1" js: dependency: transitive description: @@ -130,13 +102,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" - mime: - dependency: transitive - description: - name: mime - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" path: dependency: transitive description: @@ -144,13 +109,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" sky_engine: dependency: transitive description: flutter @@ -205,13 +163,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" - uuid: - dependency: transitive - description: - name: uuid - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.1" vector_math: dependency: transitive description: diff --git a/lib/html_editor.dart b/lib/html_editor.dart index ad6d3163..70e7af6e 100644 --- a/lib/html_editor.dart +++ b/lib/html_editor.dart @@ -18,8 +18,5 @@ export 'package:html_editor_enhanced/src/html_editor_controller_unsupported.dart if (dart.library.html) 'package:html_editor_enhanced/src/html_editor_controller_web.dart' if (dart.library.io) 'package:html_editor_enhanced/src/html_editor_controller_mobile.dart'; -/// Global variable used to get the text from the Html editor -String? text = ""; - /// Global variable used to get the [InAppWebViewController] of the Html editor Map controllerMap = {}; diff --git a/lib/src/html_editor_controller_mobile.dart b/lib/src/html_editor_controller_mobile.dart index 92919aa7..b472235e 100644 --- a/lib/src/html_editor_controller_mobile.dart +++ b/lib/src/html_editor_controller_mobile.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/foundation.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:html_editor_enhanced/html_editor.dart'; @@ -10,11 +12,18 @@ class HtmlEditorController extends unsupported.HtmlEditorController { /// outside of the package itself for endless control and customization. InAppWebViewController? get editorController => controllerMap[this]; + /// Stream to get the text once the javascript execution is complete. + /// It is *not* recommended to modify or use this property in your code, this + /// is only exposed so the [InAppWebView] can access it. + StreamController? getTextStream = StreamController.broadcast(); + /// Gets the text from the editor and returns it as a [String]. Future getText() async { - await _evaluateJavascript( + getTextStream!.stream.drain(); + _evaluateJavascript( source: "var str = \$('#summernote-2').summernote('code'); console.log(str);"); + String text = await getTextStream!.stream.first; return text; } diff --git a/lib/src/html_editor_controller_unsupported.dart b/lib/src/html_editor_controller_unsupported.dart index a5352672..17e758b5 100644 --- a/lib/src/html_editor_controller_unsupported.dart +++ b/lib/src/html_editor_controller_unsupported.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter_inappwebview/flutter_inappwebview.dart'; /// Fallback controller (should never be used) @@ -6,6 +8,11 @@ class HtmlEditorController { /// outside of the package itself for endless control and customization. InAppWebViewController? get editorController => null; + /// Stream to get the text once the javascript execution is complete. + /// It is *not* recommended to modify or use this property in your code, this + /// is only exposed so the [InAppWebView] can access it. + StreamController? getTextStream = null; + /// Gets the text from the editor and returns it as a [String]. Future getText() => Future.value(null); diff --git a/lib/src/html_editor_controller_web.dart b/lib/src/html_editor_controller_web.dart index 8dc1cee3..c41e6034 100644 --- a/lib/src/html_editor_controller_web.dart +++ b/lib/src/html_editor_controller_web.dart @@ -21,8 +21,8 @@ class HtmlEditorController extends unsupported.HtmlEditorController { _evaluateJavascriptWeb(data: {"type": "toIframe: getText"}); html.MessageEvent e = await html.window.onMessage.firstWhere( (element) => json.decode(element.data)["type"] == "toDart: getText"); - text = json.decode(e.data)["text"]; - if (text!.isEmpty || + String text = json.decode(e.data)["text"]; + if (text.isEmpty || text == "

" || text == "


" || text == "


") text = ""; diff --git a/lib/src/widgets/html_editor_widget_mobile.dart b/lib/src/widgets/html_editor_widget_mobile.dart index ca763c83..052d1320 100644 --- a/lib/src/widgets/html_editor_widget_mobile.dart +++ b/lib/src/widgets/html_editor_widget_mobile.dart @@ -64,7 +64,7 @@ class HtmlEditorWidget extends StatelessWidget { message == "


") { message = ""; } - text = message; + widgetController.getTextStream!.add(message); }, onLoadStop: (InAppWebViewController controller, Uri? uri) async { String url = uri.toString(); @@ -100,7 +100,7 @@ class HtmlEditorWidget extends StatelessWidget { String darkCSS = ""; await controller.evaluateJavascript( - source: "\$('head').append('${darkCSS}');"); + source: "\$('head').append('$darkCSS');"); } //set the text once the editor is loaded if (value != null) { diff --git a/pubspec.lock b/pubspec.lock index 7f6f2239..c8588762 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,27 +43,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.0" - device_info: - dependency: transitive - description: - name: device_info - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" - device_info_platform_interface: - dependency: transitive - description: - name: device_info_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" fake_async: dependency: transitive description: @@ -82,19 +61,12 @@ packages: name: flutter_inappwebview url: "https://pub.dartlang.org" source: hosted - version: "5.0.4-nullsafety.1" + version: "5.1.0+4" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.0" js: dependency: "direct main" description: @@ -116,13 +88,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" - mime: - dependency: transitive - description: - name: mime - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" path: dependency: transitive description: @@ -130,13 +95,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" sky_engine: dependency: transitive description: flutter @@ -191,13 +149,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" - uuid: - dependency: transitive - description: - name: uuid - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.1" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 2c646958..98eb28f3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: html_editor_enhanced description: HTML Editor Enhanced is a feature-packed HTML rich text editor for Android, iOS, and Web, backed by the Summernote library. -version: 1.5.0 +version: 1.5.0+1 homepage: https://github.com/tneotia/html-editor-enhanced environment: