From 8565b60cf91814a59fb7fbc9eec219a04a2adc7d Mon Sep 17 00:00:00 2001 From: singerdmx Date: Tue, 22 Dec 2020 18:06:19 -0800 Subject: [PATCH] Make _embedBuilder default --- app/lib/pages/home_page.dart | 20 -------------------- lib/widgets/editor.dart | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/lib/pages/home_page.dart b/app/lib/pages/home_page.dart index eb181b08..60383e94 100644 --- a/app/lib/pages/home_page.dart +++ b/app/lib/pages/home_page.dart @@ -3,9 +3,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_quill/models/documents/document.dart'; -import 'package:flutter_quill/models/documents/nodes/leaf.dart' as leaf; import 'package:flutter_quill/widgets/controller.dart'; -import 'package:flutter_quill/widgets/default_styles.dart'; import 'package:flutter_quill/widgets/editor.dart'; import 'package:flutter_quill/widgets/toolbar.dart'; @@ -77,7 +75,6 @@ class _HomePageState extends State { focusNode: _focusNode, autoFocus: true, readOnly: false, - embedBuilder: _embedBuilder, enableInteractiveSelection: true, expands: false, padding: EdgeInsets.zero, @@ -87,21 +84,4 @@ class _HomePageState extends State { ], ); } - - Widget _embedBuilder(BuildContext context, leaf.Embed node) { - switch (node.value.type) { - case 'hr': - final style = QuillStyles.getStyles(context, true); - return Divider( - height: style.paragraph.style.fontSize * style.paragraph.style.height, - thickness: 2, - color: Colors.grey.shade200, - ); - default: - throw UnimplementedError( - 'Embeddable type "${node.value.type}" is not supported by default embed ' - 'builder of QuillEditor. You must pass your own builder function to ' - 'embedBuilder property of QuillEditor or QuillField widgets.'); - } - } } diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 48449d36..f37360d0 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -19,6 +19,7 @@ import 'package:flutter_quill/widgets/text_selection.dart'; import 'box.dart'; import 'controller.dart'; import 'cursor.dart'; +import 'default_styles.dart'; import 'delegate.dart'; abstract class EditorState extends State { @@ -66,6 +67,23 @@ abstract class RenderAbstractEditor { void selectPosition(SelectionChangedCause cause); } +Widget _defaultEmbedBuilder(BuildContext context, Embed node) { + switch (node.value.type) { + case 'hr': + final style = QuillStyles.getStyles(context, true); + return Divider( + height: style.paragraph.style.fontSize * style.paragraph.style.height, + thickness: 2, + color: Colors.grey.shade200, + ); + default: + throw UnimplementedError( + 'Embeddable type "${node.value.type}" is not supported by default embed ' + 'builder of QuillEditor. You must pass your own builder function to ' + 'embedBuilder property of QuillEditor or QuillField widgets.'); + } +} + class QuillEditor extends StatefulWidget { final QuillController controller; final FocusNode focusNode; @@ -102,7 +120,7 @@ class QuillEditor extends StatefulWidget { this.keyboardAppearance = Brightness.light, this.scrollPhysics, this.onLaunchUrl, - @required this.embedBuilder}) + this.embedBuilder = _defaultEmbedBuilder}) : assert(controller != null), assert(scrollController != null), assert(scrollable != null),