From 3021fbf06024f3b7fc64d142ed03db282ce86321 Mon Sep 17 00:00:00 2001 From: Miller Adulu Date: Sat, 20 Mar 2021 01:03:19 +0300 Subject: [PATCH] Fix basic widget rendering and editor usage (#95) * Upgrade upgradable packages * Apply default null-safety migrations * Remove hashnode as a dependency and localize its functionality to the package. Maintenance was done long time ago hence no need to wait for the update * Localize ui package to reduce maintenance burdens * Replace universal html with dart:html * Remove unnecessary checks * Fix formatting * Migrate app to null safety * Enable methods to be nullable * Fix non-nullable issue with node methods * Cast as Node * Use universal html * Use universal html package to bring in the ImageElement class * Remove unused imports * Fix imports on the editor file * Add key to quill editor * Remove final from the GlobalKey * Remove final on GlobalKey * Remove custom util implementation in favor of quiver * Fix issue with null on token attrivute * Remove final hashcode that is replaced by quiver functionality * Fix merge request * Fix hit test position in text_line.dart * Fix null safety errors on text_selection.dart * Fix sound null safe errors in toolbar.dart * Import null safe file picker * Fix issue with basic text editing and editor display * Fix issues with basic widget rendering and editing --- lib/widgets/delegate.dart | 12 ++++++------ lib/widgets/editor.dart | 29 ++++++++++++++--------------- lib/widgets/text_block.dart | 2 +- lib/widgets/text_line.dart | 16 ++++++++-------- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/lib/widgets/delegate.dart b/lib/widgets/delegate.dart index a8278246..3fa51fab 100644 --- a/lib/widgets/delegate.dart +++ b/lib/widgets/delegate.dart @@ -14,7 +14,7 @@ abstract class EditorTextSelectionGestureDetectorBuilderDelegate { bool getForcePressEnabled(); - bool? getSelectionEnabled(); + bool getSelectionEnabled(); } class EditorTextSelectionGestureDetectorBuilder { @@ -43,7 +43,7 @@ class EditorTextSelectionGestureDetectorBuilder { onForcePressStart(ForcePressDetails details) { assert(delegate.getForcePressEnabled()); shouldShowSelectionToolbar = true; - if (delegate.getSelectionEnabled()!) { + if (delegate.getSelectionEnabled()) { getRenderEditor()!.selectWordsInRange( details.globalPosition, null, @@ -65,7 +65,7 @@ class EditorTextSelectionGestureDetectorBuilder { } onSingleTapUp(TapUpDetails details) { - if (delegate.getSelectionEnabled()!) { + if (delegate.getSelectionEnabled()) { getRenderEditor()!.selectWordEdge(SelectionChangedCause.tap); } } @@ -73,7 +73,7 @@ class EditorTextSelectionGestureDetectorBuilder { onSingleTapCancel() {} onSingleLongTapStart(LongPressStartDetails details) { - if (delegate.getSelectionEnabled()!) { + if (delegate.getSelectionEnabled()) { getRenderEditor()!.selectPositionAt( details.globalPosition, null, @@ -83,7 +83,7 @@ class EditorTextSelectionGestureDetectorBuilder { } onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { - if (delegate.getSelectionEnabled()!) { + if (delegate.getSelectionEnabled()) { getRenderEditor()!.selectPositionAt( details.globalPosition, null, @@ -99,7 +99,7 @@ class EditorTextSelectionGestureDetectorBuilder { } onDoubleTapDown(TapDownDetails details) { - if (delegate.getSelectionEnabled()!) { + if (delegate.getSelectionEnabled()) { getRenderEditor()!.selectWord(SelectionChangedCause.tap); if (shouldShowSelectionToolbar) { getEditor()!.showToolbar(); diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 12b698bf..2cc6258c 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -149,7 +149,7 @@ class QuillEditor extends StatefulWidget { final bool? showCursor; final bool readOnly; final String? placeholder; - final bool? enableInteractiveSelection; + final bool enableInteractiveSelection; final double? minHeight; final double? maxHeight; final DefaultStyles? customStyles; @@ -161,8 +161,7 @@ class QuillEditor extends StatefulWidget { final EmbedBuilder embedBuilder; QuillEditor( - {Key? key, - required this.controller, + {required this.controller, required this.focusNode, required this.scrollController, required this.scrollable, @@ -171,7 +170,7 @@ class QuillEditor extends StatefulWidget { this.showCursor, required this.readOnly, this.placeholder, - this.enableInteractiveSelection, + this.enableInteractiveSelection = true, this.minHeight, this.maxHeight, this.customStyles, @@ -184,7 +183,7 @@ class QuillEditor extends StatefulWidget { kIsWeb ? _defaultEmbedBuilderWeb : _defaultEmbedBuilder}); factory QuillEditor.basic( - {Key? key, required QuillController controller, required bool readOnly}) { + {required QuillController controller, required bool readOnly}) { return QuillEditor( controller: controller, scrollController: ScrollController(), @@ -270,10 +269,10 @@ class _QuillEditorState extends State widget.placeholder, widget.onLaunchUrl, ToolbarOptions( - copy: widget.enableInteractiveSelection ?? true, - cut: widget.enableInteractiveSelection ?? true, - paste: widget.enableInteractiveSelection ?? true, - selectAll: widget.enableInteractiveSelection ?? true, + copy: widget.enableInteractiveSelection, + cut: widget.enableInteractiveSelection, + paste: widget.enableInteractiveSelection, + selectAll: widget.enableInteractiveSelection, ), theme.platform == TargetPlatform.iOS || theme.platform == TargetPlatform.android, @@ -296,7 +295,7 @@ class _QuillEditorState extends State selectionColor, textSelectionControls, widget.keyboardAppearance, - widget.enableInteractiveSelection!, + widget.enableInteractiveSelection, widget.scrollPhysics, widget.embedBuilder), ); @@ -313,7 +312,7 @@ class _QuillEditorState extends State } @override - bool? getSelectionEnabled() { + bool getSelectionEnabled() { return widget.enableInteractiveSelection; } @@ -331,7 +330,7 @@ class _QuillEditorSelectionGestureDetectorBuilder @override onForcePressStart(ForcePressDetails details) { super.onForcePressStart(details); - if (delegate.getSelectionEnabled()! && shouldShowSelectionToolbar) { + if (delegate.getSelectionEnabled() && shouldShowSelectionToolbar) { getEditor()!.showToolbar(); } } @@ -341,7 +340,7 @@ class _QuillEditorSelectionGestureDetectorBuilder @override void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { - if (!delegate.getSelectionEnabled()!) { + if (!delegate.getSelectionEnabled()) { return; } switch (Theme.of(_state.context).platform) { @@ -470,7 +469,7 @@ class _QuillEditorSelectionGestureDetectorBuilder bool positionSelected = _onTapping(details); - if (delegate.getSelectionEnabled()! && !positionSelected) { + if (delegate.getSelectionEnabled() && !positionSelected) { switch (Theme.of(_state.context).platform) { case TargetPlatform.iOS: case TargetPlatform.macOS: @@ -499,7 +498,7 @@ class _QuillEditorSelectionGestureDetectorBuilder @override void onSingleLongTapStart(LongPressStartDetails details) { - if (delegate.getSelectionEnabled()!) { + if (delegate.getSelectionEnabled()) { switch (Theme.of(_state.context).platform) { case TargetPlatform.iOS: case TargetPlatform.macOS: diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index 6a12559f..ee71e6e5 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -107,7 +107,7 @@ class EditableTextBlock extends StatelessWidget { int count = block.children.length; var children = []; int index = 0; - for (Line line in block.children as Iterable) { + for (Line line in Iterable.castFrom(block.children)) { index++; EditableTextLine editableTextLine = EditableTextLine( line, diff --git a/lib/widgets/text_line.dart b/lib/widgets/text_line.dart index 8eb7207e..ea676d64 100644 --- a/lib/widgets/text_line.dart +++ b/lib/widgets/text_line.dart @@ -101,7 +101,7 @@ class TextLine extends StatelessWidget { Attribute.h3: defaultStyles.h3!.style, }; - textStyle = textStyle.merge(m[header!] ?? defaultStyles.paragraph!.style); + textStyle = textStyle.merge(m[header] ?? defaultStyles.paragraph!.style); Attribute? block = line.style.getBlockExceptHeader(); TextStyle? toMerge; @@ -187,8 +187,8 @@ class TextLine extends StatelessWidget { decorations.add(b.decoration); } return a.merge(b).apply( - decoration: - TextDecoration.combine(decorations as List)); + decoration: TextDecoration.combine( + List.castFrom(decorations))); } } @@ -824,8 +824,8 @@ class _TextLineElement extends RenderObjectElement { } @override - insertRenderObjectChild(RenderObject child, TextLineSlot? slot) { - assert(child is RenderBox); + insertRenderObjectChild(RenderBox child, TextLineSlot? slot) { + // assert(child is RenderBox); _updateRenderObject(child, slot); assert(renderObject.children.keys.contains(slot)); } @@ -854,13 +854,13 @@ class _TextLineElement extends RenderObjectElement { } } - _updateRenderObject(RenderObject? child, TextLineSlot? slot) { + _updateRenderObject(RenderBox? child, TextLineSlot? slot) { switch (slot) { case TextLineSlot.LEADING: - renderObject.setLeading(child as RenderBox?); + renderObject.setLeading(child); break; case TextLineSlot.BODY: - renderObject.setBody((child as RenderBox?) as RenderContentProxyBox?); + renderObject.setBody((child) as RenderContentProxyBox?); break; default: throw UnimplementedError();