Make _embedBuilder default

pull/13/head
singerdmx 4 years ago
parent 6b806fdb2a
commit 8565b60cf9
  1. 20
      app/lib/pages/home_page.dart
  2. 20
      lib/widgets/editor.dart

@ -3,9 +3,7 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_quill/models/documents/document.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/controller.dart';
import 'package:flutter_quill/widgets/default_styles.dart';
import 'package:flutter_quill/widgets/editor.dart'; import 'package:flutter_quill/widgets/editor.dart';
import 'package:flutter_quill/widgets/toolbar.dart'; import 'package:flutter_quill/widgets/toolbar.dart';
@ -77,7 +75,6 @@ class _HomePageState extends State<HomePage> {
focusNode: _focusNode, focusNode: _focusNode,
autoFocus: true, autoFocus: true,
readOnly: false, readOnly: false,
embedBuilder: _embedBuilder,
enableInteractiveSelection: true, enableInteractiveSelection: true,
expands: false, expands: false,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@ -87,21 +84,4 @@ class _HomePageState extends State<HomePage> {
], ],
); );
} }
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.');
}
}
} }

@ -19,6 +19,7 @@ import 'package:flutter_quill/widgets/text_selection.dart';
import 'box.dart'; import 'box.dart';
import 'controller.dart'; import 'controller.dart';
import 'cursor.dart'; import 'cursor.dart';
import 'default_styles.dart';
import 'delegate.dart'; import 'delegate.dart';
abstract class EditorState extends State<RawEditor> { abstract class EditorState extends State<RawEditor> {
@ -66,6 +67,23 @@ abstract class RenderAbstractEditor {
void selectPosition(SelectionChangedCause cause); 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 { class QuillEditor extends StatefulWidget {
final QuillController controller; final QuillController controller;
final FocusNode focusNode; final FocusNode focusNode;
@ -102,7 +120,7 @@ class QuillEditor extends StatefulWidget {
this.keyboardAppearance = Brightness.light, this.keyboardAppearance = Brightness.light,
this.scrollPhysics, this.scrollPhysics,
this.onLaunchUrl, this.onLaunchUrl,
@required this.embedBuilder}) this.embedBuilder = _defaultEmbedBuilder})
: assert(controller != null), : assert(controller != null),
assert(scrollController != null), assert(scrollController != null),
assert(scrollable != null), assert(scrollable != null),

Loading…
Cancel
Save