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/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<HomePage> {
focusNode: _focusNode,
autoFocus: true,
readOnly: false,
embedBuilder: _embedBuilder,
enableInteractiveSelection: true,
expands: false,
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 'controller.dart';
import 'cursor.dart';
import 'default_styles.dart';
import 'delegate.dart';
abstract class EditorState extends State<RawEditor> {
@ -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),

Loading…
Cancel
Save