Skip to content

Commit

Permalink
Merge pull request #3 from tneotia/nullsafety
Browse files Browse the repository at this point in the history
Minor fix for getText null
  • Loading branch information
tneotia authored Mar 10, 2021
2 parents 0d4e87f + 0aeb442 commit 740847f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 110 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
53 changes: 2 additions & 51 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,13 @@ 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:
name: cupertino_icons
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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -130,27 +102,13 @@ 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:
name: path
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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions lib/html_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<HtmlEditorController, dynamic> controllerMap = {};
11 changes: 10 additions & 1 deletion lib/src/html_editor_controller_mobile.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<String>? getTextStream = StreamController<String>.broadcast();

/// Gets the text from the editor and returns it as a [String].
Future<String?> 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;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/src/html_editor_controller_unsupported.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter_inappwebview/flutter_inappwebview.dart';

/// Fallback controller (should never be used)
Expand All @@ -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<String>? getTextStream = null;

/// Gets the text from the editor and returns it as a [String].
Future<String?> getText() => Future.value(null);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/html_editor_controller_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<p></p>" ||
text == "<p><br></p>" ||
text == "<p><br/></p>") text = "";
Expand Down
4 changes: 2 additions & 2 deletions lib/src/widgets/html_editor_widget_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class HtmlEditorWidget extends StatelessWidget {
message == "<p><br/></p>") {
message = "";
}
text = message;
widgetController.getTextStream!.add(message);
},
onLoadStop: (InAppWebViewController controller, Uri? uri) async {
String url = uri.toString();
Expand Down Expand Up @@ -100,7 +100,7 @@ class HtmlEditorWidget extends StatelessWidget {
String darkCSS =
"<link href=\"summernote-lite-dark.css\" rel=\"stylesheet\">";
await controller.evaluateJavascript(
source: "\$('head').append('${darkCSS}');");
source: "\$('head').append('$darkCSS');");
}
//set the text once the editor is loaded
if (value != null) {
Expand Down
51 changes: 1 addition & 50 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -116,27 +88,13 @@ 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:
name: path
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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 740847f

Please sign in to comment.