From fdb4b45ab9641efdfd2929b66b570650fb73f3a9 Mon Sep 17 00:00:00 2001 From: Tanay Neotia Date: Sat, 30 Oct 2021 16:39:40 -0400 Subject: [PATCH] Fix formatting and try again to improve pub score --- lib/html_editor.dart | 2 +- .../html_editor_controller_unsupported.dart | 3 +- lib/src/html_editor_controller_web.dart | 5 +- .../widgets/html_editor_widget_mobile.dart | 15 +- lib/src/widgets/toolbar_widget.dart | 174 +++++++++--------- .../shims/flutter_inappwebview_fake.dart | 23 ++- pubspec.yaml | 2 +- 7 files changed, 112 insertions(+), 112 deletions(-) diff --git a/lib/html_editor.dart b/lib/html_editor.dart index 4a9cb979..c11e5afc 100644 --- a/lib/html_editor.dart +++ b/lib/html_editor.dart @@ -18,7 +18,7 @@ export 'package:html_editor_enhanced/src/html_editor_controller_unsupported.dart if (dart.library.io) 'package:html_editor_enhanced/src/html_editor_controller_mobile.dart'; export 'package:html_editor_enhanced/utils/shims/flutter_inappwebview_fake.dart' - if (dart.library.io) 'package:flutter_inappwebview/flutter_inappwebview.dart'; + if (dart.library.io) 'package:flutter_inappwebview/flutter_inappwebview.dart'; /// Defines the 3 different cases for file insertion failing enum UploadError { unsupportedFile, exceededMaxSize, jsException } diff --git a/lib/src/html_editor_controller_unsupported.dart b/lib/src/html_editor_controller_unsupported.dart index 00f42077..66566773 100644 --- a/lib/src/html_editor_controller_unsupported.dart +++ b/lib/src/html_editor_controller_unsupported.dart @@ -97,7 +97,8 @@ class HtmlEditorController { /// [withHtmlTags] may not work properly when the selected text is entirely /// within one HTML tag. However if the selected text spans multiple different /// tags, it should work as expected. - Future getSelectedTextWeb({bool withHtmlTags = false}) => Future.value(''); + Future getSelectedTextWeb({bool withHtmlTags = false}) => + Future.value(''); /// Insert HTML at the position of the cursor in the editor /// Note: This method should not be used for plaintext strings diff --git a/lib/src/html_editor_controller_web.dart b/lib/src/html_editor_controller_web.dart index 3a26d9f1..0153ba38 100644 --- a/lib/src/html_editor_controller_web.dart +++ b/lib/src/html_editor_controller_web.dart @@ -3,7 +3,6 @@ import 'dart:convert'; import 'dart:html' as html; import 'package:flutter/foundation.dart'; -import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:html_editor_enhanced/html_editor.dart'; import 'package:html_editor_enhanced/src/html_editor_controller_unsupported.dart' as unsupported; @@ -75,8 +74,8 @@ class HtmlEditorController extends unsupported.HtmlEditorController { } else { _evaluateJavascriptWeb(data: {'type': 'toIframe: getSelectedText'}); } - var e = await html.window.onMessage.firstWhere( - (element) => json.decode(element.data)['type'] == 'toDart: getSelectedText'); + var e = await html.window.onMessage.firstWhere((element) => + json.decode(element.data)['type'] == 'toDart: getSelectedText'); return json.decode(e.data)['text']; } diff --git a/lib/src/widgets/html_editor_widget_mobile.dart b/lib/src/widgets/html_editor_widget_mobile.dart index 4d84c369..b38055b9 100644 --- a/lib/src/widgets/html_editor_widget_mobile.dart +++ b/lib/src/widgets/html_editor_widget_mobile.dart @@ -8,7 +8,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; -import 'package:html_editor_enhanced/html_editor.dart' hide NavigationActionPolicy, UserScript, ContextMenu; +import 'package:html_editor_enhanced/html_editor.dart' + hide NavigationActionPolicy, UserScript, ContextMenu; import 'package:html_editor_enhanced/src/widgets/toolbar_widget.dart'; import 'package:html_editor_enhanced/utils/utils.dart'; import 'package:html_editor_enhanced/utils/plugins.dart'; @@ -156,9 +157,9 @@ class _HtmlEditorWidgetMobileState extends State { )), initialUserScripts: widget.htmlEditorOptions.mobileInitialScripts - as UnmodifiableListView?, + as UnmodifiableListView?, contextMenu: widget.htmlEditorOptions.mobileContextMenu - as ContextMenu?, + as ContextMenu?, gestureRecognizers: { Factory( () => VerticalDragGestureRecognizer()), @@ -170,8 +171,9 @@ class _HtmlEditorWidgetMobileState extends State { shouldOverrideUrlLoading: (controller, action) async { if (!action.request.url.toString().contains(filePath)) { return (await widget.callbacks?.onNavigationRequestMobile - ?.call(action.request.url.toString())) - as NavigationActionPolicy? ?? NavigationActionPolicy.ALLOW; + ?.call(action.request.url.toString())) + as NavigationActionPolicy? ?? + NavigationActionPolicy.ALLOW; } return NavigationActionPolicy.ALLOW; }, @@ -189,8 +191,7 @@ class _HtmlEditorWidgetMobileState extends State { mounted && !visibleStream.isClosed) { Future setHeightJS() async { - await controller.evaluateJavascript( - source: """ + await controller.evaluateJavascript(source: """ \$('div.note-editable').outerHeight(${max(docHeight - (toolbarKey.currentContext?.size?.height ?? 0), 30)}); // from https://stackoverflow.com/a/67152280 var selection = window.getSelection(); diff --git a/lib/src/widgets/toolbar_widget.dart b/lib/src/widgets/toolbar_widget.dart index fba1fa73..b458458e 100644 --- a/lib/src/widgets/toolbar_widget.dart +++ b/lib/src/widgets/toolbar_widget.dart @@ -1101,108 +1101,108 @@ class ToolbarWidgetState extends State { newColor = _backColorSelected; } await showDialog( - context: context, - builder: (BuildContext context) { - return PointerInterceptor( - child: AlertDialog( - scrollable: true, - content: ColorPicker( - color: newColor, - onColorChanged: (color) { - newColor = color; - }, - title: Text('Choose a Color', - style: Theme.of(context).textTheme.headline6), - width: 40, - height: 40, - spacing: 0, - runSpacing: 0, - borderRadius: 0, - wheelDiameter: 165, - enableOpacity: false, - showColorCode: true, - colorCodeHasColor: true, - pickersEnabled: { - ColorPickerType.wheel: true, - }, - copyPasteBehavior: const ColorPickerCopyPasteBehavior( - parseShortHexCode: true, - ), - actionButtons: const ColorPickerActionButtons( - dialogActionButtons: true, - ), - ), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); + context: context, + builder: (BuildContext context) { + return PointerInterceptor( + child: AlertDialog( + scrollable: true, + content: ColorPicker( + color: newColor, + onColorChanged: (color) { + newColor = color; }, - child: Text('Cancel'), + title: Text('Choose a Color', + style: Theme.of(context).textTheme.headline6), + width: 40, + height: 40, + spacing: 0, + runSpacing: 0, + borderRadius: 0, + wheelDiameter: 165, + enableOpacity: false, + showColorCode: true, + colorCodeHasColor: true, + pickersEnabled: { + ColorPickerType.wheel: true, + }, + copyPasteBehavior: + const ColorPickerCopyPasteBehavior( + parseShortHexCode: true, + ), + actionButtons: const ColorPickerActionButtons( + dialogActionButtons: true, + ), ), - TextButton( + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text('Cancel'), + ), + TextButton( + onPressed: () { + if (t.getIcons()[index].icon == + Icons.format_color_text) { + setState(mounted, this.setState, () { + _foreColorSelected = Colors.black; + }); + widget.controller.execCommand( + 'removeFormat', + argument: 'foreColor'); + widget.controller.execCommand('foreColor', + argument: 'initial'); + } + if (t.getIcons()[index].icon == + Icons.format_color_fill) { + setState(mounted, this.setState, () { + _backColorSelected = Colors.yellow; + }); + widget.controller.execCommand( + 'removeFormat', + argument: 'hiliteColor'); + widget.controller.execCommand('hiliteColor', + argument: 'initial'); + } + Navigator.of(context).pop(); + }, + child: Text('Reset to default color')), + TextButton( onPressed: () { if (t.getIcons()[index].icon == Icons.format_color_text) { + widget.controller.execCommand('foreColor', + argument: (newColor.value & 0xFFFFFF) + .toRadixString(16) + .padLeft(6, '0') + .toUpperCase()); setState(mounted, this.setState, () { - _foreColorSelected = Colors.black; + _foreColorSelected = newColor; }); - widget.controller.execCommand( - 'removeFormat', - argument: 'foreColor'); - widget.controller.execCommand('foreColor', - argument: 'initial'); } if (t.getIcons()[index].icon == Icons.format_color_fill) { + widget.controller.execCommand('hiliteColor', + argument: (newColor.value & 0xFFFFFF) + .toRadixString(16) + .padLeft(6, '0') + .toUpperCase()); setState(mounted, this.setState, () { - _backColorSelected = Colors.yellow; + _backColorSelected = newColor; }); - widget.controller.execCommand( - 'removeFormat', - argument: 'hiliteColor'); - widget.controller.execCommand('hiliteColor', - argument: 'initial'); } - Navigator.of(context).pop(); - }, - child: Text('Reset to default color')), - TextButton( - onPressed: () { - if (t.getIcons()[index].icon == - Icons.format_color_text) { - widget.controller.execCommand('foreColor', - argument: (newColor.value & 0xFFFFFF) - .toRadixString(16) - .padLeft(6, '0') - .toUpperCase()); setState(mounted, this.setState, () { - _foreColorSelected = newColor; + _colorSelected[index] = + !_colorSelected[index]; }); - } - if (t.getIcons()[index].icon == - Icons.format_color_fill) { - widget.controller.execCommand('hiliteColor', - argument: (newColor.value & 0xFFFFFF) - .toRadixString(16) - .padLeft(6, '0') - .toUpperCase()); - setState(mounted, this.setState, () { - _backColorSelected = newColor; - }); - } - setState(mounted, this.setState, () { - _colorSelected[index] = - !_colorSelected[index]; - }); - Navigator.of(context).pop(); - }, - child: Text('Set color'), - ) - ], - ), - ); - } - ); + Navigator.of(context).pop(); + }, + child: Text('Set color'), + ) + ], + ), + ); + }); } } }, diff --git a/lib/utils/shims/flutter_inappwebview_fake.dart b/lib/utils/shims/flutter_inappwebview_fake.dart index a9b98726..cefeee0c 100644 --- a/lib/utils/shims/flutter_inappwebview_fake.dart +++ b/lib/utils/shims/flutter_inappwebview_fake.dart @@ -33,8 +33,7 @@ class ContextMenu { ///Event fired when the context menu for this WebView is being built. /// ///[hitTestResult] represents the hit result for hitting an HTML elements. - final void Function(dynamic hitTestResult)? - onCreateContextMenu; + final void Function(dynamic hitTestResult)? onCreateContextMenu; ///Event fired when the context menu for this WebView is being hidden. final void Function()? onHideContextMenu; @@ -43,7 +42,7 @@ class ContextMenu { /// ///[contextMenuItemClicked] represents the [ContextMenuItem] clicked. final void Function(ContextMenuItem contextMenuItemClicked)? - onContextMenuActionItemClicked; + onContextMenuActionItemClicked; ///Context menu options. final ContextMenuOptions? options; @@ -53,10 +52,10 @@ class ContextMenu { ContextMenu( {this.menuItems = const [], - this.onCreateContextMenu, - this.onHideContextMenu, - this.options, - this.onContextMenuActionItemClicked}); + this.onCreateContextMenu, + this.onHideContextMenu, + this.options, + this.onContextMenuActionItemClicked}); Map toMap() { return { @@ -206,10 +205,10 @@ class UserScript { UserScript( {this.groupName, - required this.source, - required this.injectionTime, - this.iosForMainFrameOnly = true, - ContentWorld? contentWorld}) { + required this.source, + required this.injectionTime, + this.iosForMainFrameOnly = true, + ContentWorld? contentWorld}) { this.contentWorld = contentWorld ?? ContentWorld.PAGE; } @@ -261,7 +260,7 @@ class ContentWorld { ///The default world for clients. // ignore: non_constant_identifier_names static final ContentWorld DEFAULT_CLIENT = - ContentWorld.world(name: 'defaultClient'); + ContentWorld.world(name: 'defaultClient'); ///The content world for the current webpage’s content. ///This property contains the content world for scripts that the current webpage executes. diff --git a/pubspec.yaml b/pubspec.yaml index 07b21789..cb935ccf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: html_editor_enhanced description: HTML rich text editor for Android, iOS, and Web, using the Summernote library. Enhanced with highly customizable widget-based controls, bug fixes, callbacks, dark mode, and more. -version: 2.4.0 +version: 2.4.0+1 homepage: https://github.com/tneotia/html-editor-enhanced environment: