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
pull/97/head
Miller Adulu 4 years ago committed by GitHub
parent c593026fd9
commit 3021fbf060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      lib/widgets/delegate.dart
  2. 29
      lib/widgets/editor.dart
  3. 2
      lib/widgets/text_block.dart
  4. 16
      lib/widgets/text_line.dart

@ -14,7 +14,7 @@ abstract class EditorTextSelectionGestureDetectorBuilderDelegate {
bool getForcePressEnabled(); bool getForcePressEnabled();
bool? getSelectionEnabled(); bool getSelectionEnabled();
} }
class EditorTextSelectionGestureDetectorBuilder { class EditorTextSelectionGestureDetectorBuilder {
@ -43,7 +43,7 @@ class EditorTextSelectionGestureDetectorBuilder {
onForcePressStart(ForcePressDetails details) { onForcePressStart(ForcePressDetails details) {
assert(delegate.getForcePressEnabled()); assert(delegate.getForcePressEnabled());
shouldShowSelectionToolbar = true; shouldShowSelectionToolbar = true;
if (delegate.getSelectionEnabled()!) { if (delegate.getSelectionEnabled()) {
getRenderEditor()!.selectWordsInRange( getRenderEditor()!.selectWordsInRange(
details.globalPosition, details.globalPosition,
null, null,
@ -65,7 +65,7 @@ class EditorTextSelectionGestureDetectorBuilder {
} }
onSingleTapUp(TapUpDetails details) { onSingleTapUp(TapUpDetails details) {
if (delegate.getSelectionEnabled()!) { if (delegate.getSelectionEnabled()) {
getRenderEditor()!.selectWordEdge(SelectionChangedCause.tap); getRenderEditor()!.selectWordEdge(SelectionChangedCause.tap);
} }
} }
@ -73,7 +73,7 @@ class EditorTextSelectionGestureDetectorBuilder {
onSingleTapCancel() {} onSingleTapCancel() {}
onSingleLongTapStart(LongPressStartDetails details) { onSingleLongTapStart(LongPressStartDetails details) {
if (delegate.getSelectionEnabled()!) { if (delegate.getSelectionEnabled()) {
getRenderEditor()!.selectPositionAt( getRenderEditor()!.selectPositionAt(
details.globalPosition, details.globalPosition,
null, null,
@ -83,7 +83,7 @@ class EditorTextSelectionGestureDetectorBuilder {
} }
onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) {
if (delegate.getSelectionEnabled()!) { if (delegate.getSelectionEnabled()) {
getRenderEditor()!.selectPositionAt( getRenderEditor()!.selectPositionAt(
details.globalPosition, details.globalPosition,
null, null,
@ -99,7 +99,7 @@ class EditorTextSelectionGestureDetectorBuilder {
} }
onDoubleTapDown(TapDownDetails details) { onDoubleTapDown(TapDownDetails details) {
if (delegate.getSelectionEnabled()!) { if (delegate.getSelectionEnabled()) {
getRenderEditor()!.selectWord(SelectionChangedCause.tap); getRenderEditor()!.selectWord(SelectionChangedCause.tap);
if (shouldShowSelectionToolbar) { if (shouldShowSelectionToolbar) {
getEditor()!.showToolbar(); getEditor()!.showToolbar();

@ -149,7 +149,7 @@ class QuillEditor extends StatefulWidget {
final bool? showCursor; final bool? showCursor;
final bool readOnly; final bool readOnly;
final String? placeholder; final String? placeholder;
final bool? enableInteractiveSelection; final bool enableInteractiveSelection;
final double? minHeight; final double? minHeight;
final double? maxHeight; final double? maxHeight;
final DefaultStyles? customStyles; final DefaultStyles? customStyles;
@ -161,8 +161,7 @@ class QuillEditor extends StatefulWidget {
final EmbedBuilder embedBuilder; final EmbedBuilder embedBuilder;
QuillEditor( QuillEditor(
{Key? key, {required this.controller,
required this.controller,
required this.focusNode, required this.focusNode,
required this.scrollController, required this.scrollController,
required this.scrollable, required this.scrollable,
@ -171,7 +170,7 @@ class QuillEditor extends StatefulWidget {
this.showCursor, this.showCursor,
required this.readOnly, required this.readOnly,
this.placeholder, this.placeholder,
this.enableInteractiveSelection, this.enableInteractiveSelection = true,
this.minHeight, this.minHeight,
this.maxHeight, this.maxHeight,
this.customStyles, this.customStyles,
@ -184,7 +183,7 @@ class QuillEditor extends StatefulWidget {
kIsWeb ? _defaultEmbedBuilderWeb : _defaultEmbedBuilder}); kIsWeb ? _defaultEmbedBuilderWeb : _defaultEmbedBuilder});
factory QuillEditor.basic( factory QuillEditor.basic(
{Key? key, required QuillController controller, required bool readOnly}) { {required QuillController controller, required bool readOnly}) {
return QuillEditor( return QuillEditor(
controller: controller, controller: controller,
scrollController: ScrollController(), scrollController: ScrollController(),
@ -270,10 +269,10 @@ class _QuillEditorState extends State<QuillEditor>
widget.placeholder, widget.placeholder,
widget.onLaunchUrl, widget.onLaunchUrl,
ToolbarOptions( ToolbarOptions(
copy: widget.enableInteractiveSelection ?? true, copy: widget.enableInteractiveSelection,
cut: widget.enableInteractiveSelection ?? true, cut: widget.enableInteractiveSelection,
paste: widget.enableInteractiveSelection ?? true, paste: widget.enableInteractiveSelection,
selectAll: widget.enableInteractiveSelection ?? true, selectAll: widget.enableInteractiveSelection,
), ),
theme.platform == TargetPlatform.iOS || theme.platform == TargetPlatform.iOS ||
theme.platform == TargetPlatform.android, theme.platform == TargetPlatform.android,
@ -296,7 +295,7 @@ class _QuillEditorState extends State<QuillEditor>
selectionColor, selectionColor,
textSelectionControls, textSelectionControls,
widget.keyboardAppearance, widget.keyboardAppearance,
widget.enableInteractiveSelection!, widget.enableInteractiveSelection,
widget.scrollPhysics, widget.scrollPhysics,
widget.embedBuilder), widget.embedBuilder),
); );
@ -313,7 +312,7 @@ class _QuillEditorState extends State<QuillEditor>
} }
@override @override
bool? getSelectionEnabled() { bool getSelectionEnabled() {
return widget.enableInteractiveSelection; return widget.enableInteractiveSelection;
} }
@ -331,7 +330,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
@override @override
onForcePressStart(ForcePressDetails details) { onForcePressStart(ForcePressDetails details) {
super.onForcePressStart(details); super.onForcePressStart(details);
if (delegate.getSelectionEnabled()! && shouldShowSelectionToolbar) { if (delegate.getSelectionEnabled() && shouldShowSelectionToolbar) {
getEditor()!.showToolbar(); getEditor()!.showToolbar();
} }
} }
@ -341,7 +340,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
@override @override
void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) {
if (!delegate.getSelectionEnabled()!) { if (!delegate.getSelectionEnabled()) {
return; return;
} }
switch (Theme.of(_state.context).platform) { switch (Theme.of(_state.context).platform) {
@ -470,7 +469,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
bool positionSelected = _onTapping(details); bool positionSelected = _onTapping(details);
if (delegate.getSelectionEnabled()! && !positionSelected) { if (delegate.getSelectionEnabled() && !positionSelected) {
switch (Theme.of(_state.context).platform) { switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS: case TargetPlatform.iOS:
case TargetPlatform.macOS: case TargetPlatform.macOS:
@ -499,7 +498,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
@override @override
void onSingleLongTapStart(LongPressStartDetails details) { void onSingleLongTapStart(LongPressStartDetails details) {
if (delegate.getSelectionEnabled()!) { if (delegate.getSelectionEnabled()) {
switch (Theme.of(_state.context).platform) { switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS: case TargetPlatform.iOS:
case TargetPlatform.macOS: case TargetPlatform.macOS:

@ -107,7 +107,7 @@ class EditableTextBlock extends StatelessWidget {
int count = block.children.length; int count = block.children.length;
var children = <Widget>[]; var children = <Widget>[];
int index = 0; int index = 0;
for (Line line in block.children as Iterable<Line>) { for (Line line in Iterable.castFrom<dynamic, Line>(block.children)) {
index++; index++;
EditableTextLine editableTextLine = EditableTextLine( EditableTextLine editableTextLine = EditableTextLine(
line, line,

@ -101,7 +101,7 @@ class TextLine extends StatelessWidget {
Attribute.h3: defaultStyles.h3!.style, 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(); Attribute? block = line.style.getBlockExceptHeader();
TextStyle? toMerge; TextStyle? toMerge;
@ -187,8 +187,8 @@ class TextLine extends StatelessWidget {
decorations.add(b.decoration); decorations.add(b.decoration);
} }
return a.merge(b).apply( return a.merge(b).apply(
decoration: decoration: TextDecoration.combine(
TextDecoration.combine(decorations as List<TextDecoration>)); List.castFrom<dynamic, TextDecoration>(decorations)));
} }
} }
@ -824,8 +824,8 @@ class _TextLineElement extends RenderObjectElement {
} }
@override @override
insertRenderObjectChild(RenderObject child, TextLineSlot? slot) { insertRenderObjectChild(RenderBox child, TextLineSlot? slot) {
assert(child is RenderBox); // assert(child is RenderBox);
_updateRenderObject(child, slot); _updateRenderObject(child, slot);
assert(renderObject.children.keys.contains(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) { switch (slot) {
case TextLineSlot.LEADING: case TextLineSlot.LEADING:
renderObject.setLeading(child as RenderBox?); renderObject.setLeading(child);
break; break;
case TextLineSlot.BODY: case TextLineSlot.BODY:
renderObject.setBody((child as RenderBox?) as RenderContentProxyBox?); renderObject.setBody((child) as RenderContentProxyBox?);
break; break;
default: default:
throw UnimplementedError(); throw UnimplementedError();

Loading…
Cancel
Save