From c907f0cce4da036f670117a274f18ce2edc370f2 Mon Sep 17 00:00:00 2001 From: singerdmx Date: Fri, 18 Dec 2020 19:51:05 -0800 Subject: [PATCH] Add QuillTheme class --- lib/widgets/default_styles.dart | 26 ++++++++++++ lib/widgets/editor.dart | 70 ++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/lib/widgets/default_styles.dart b/lib/widgets/default_styles.dart index 5b4f8d1a..014fe486 100644 --- a/lib/widgets/default_styles.dart +++ b/lib/widgets/default_styles.dart @@ -2,6 +2,32 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:tuple/tuple.dart'; +class QuillTheme extends InheritedWidget { + final DefaultStyles data; + + QuillTheme({ + Key key, + @required this.data, + @required Widget child, + }) : assert(data != null), + assert(child != null), + super(key: key, child: child); + + @override + bool updateShouldNotify(QuillTheme oldWidget) { + return data != oldWidget.data; + } + + static DefaultStyles of(BuildContext context, nullOk) { + var widget = context.dependOnInheritedWidgetOfExactType(); + if (widget == null && nullOk) { + return null; + } + assert(widget != null); + return widget.data; + } +} + class DefaultTextBlockStyle { final TextStyle style; diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 7a29e5cb..4327c7e4 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -694,7 +694,10 @@ class RawEditorState extends EditorState @override Widget build(BuildContext context) { - // TODO: implement build + assert(debugCheckHasMediaQuery(context)); + _focusAttachment.reparent(); + super.build(context); + throw UnimplementedError(); } @@ -731,6 +734,17 @@ class RawEditorState extends EditorState widget.focusNode.addListener(_handleFocusChanged); } + @override + didChangeDependencies() { + // TODO + } + + @override + void didUpdateWidget(RawEditor oldWidget) { + super.didUpdateWidget(oldWidget); + // TODO + } + handleDelete(bool forward) { // TODO } @@ -834,11 +848,40 @@ class RawEditorState extends EditorState bool get wantKeepAlive => widget.focusNode.hasFocus; } +typedef TextSelectionChangedHandler = void Function( + TextSelection selection, SelectionChangedCause cause); + class RenderEditor extends RenderEditableContainerBox implements RenderAbstractEditor { Document document; TextSelection selection; bool _hasFocus = false; + LayerLink _startHandleLayerLink; + LayerLink _endHandleLayerLink; + TextSelectionChangedHandler onSelectionChanged; + + RenderEditor( + List children, + TextDirection textDirection, + hasFocus, + EdgeInsetsGeometry padding, + this.document, + this.selection, + this._hasFocus, + this.onSelectionChanged, + this._startHandleLayerLink, + this._endHandleLayerLink, + EdgeInsets floatingCursorAddedMargin) + : assert(document != null), + assert(textDirection != null), + assert(hasFocus != null), + assert(floatingCursorAddedMargin != null), + super( + children, + document.root, + textDirection, + padding, + ); setDocument(Document doc) { assert(doc != null); @@ -866,6 +909,22 @@ class RenderEditor extends RenderEditableContainerBox markNeedsPaint(); } + setStartHandleLayerLink(LayerLink value) { + if (_startHandleLayerLink == value) { + return; + } + _startHandleLayerLink = value; + markNeedsPaint(); + } + + setEndHandleLayerLink(LayerLink value) { + if (_endHandleLayerLink == value) { + return; + } + _endHandleLayerLink = value; + markNeedsPaint(); + } + @override List getEndpointsForSelection( TextSelection textSelection) { @@ -943,6 +1002,15 @@ class RenderEditableContainerBox extends RenderBox EdgeInsetsGeometry _padding; EdgeInsets _resolvedPadding; + RenderEditableContainerBox(List children, this._container, + this._textDirection, this._padding) + : assert(_container != null), + assert(_textDirection != null), + assert(_padding != null), + assert(_padding.isNonNegative) { + addAll(children); + } + setContainer(container.Container c) { assert(c != null); if (_container == c) {