Add EmbedBuilder

pull/13/head
singerdmx 4 years ago
parent d82c84d7b1
commit 4b9975fb95
  1. 3
      lib/widgets/delegate.dart
  2. 15
      lib/widgets/editor.dart
  3. 8
      lib/widgets/text_block.dart
  4. 11
      lib/widgets/text_line.dart

@ -1,7 +1,10 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter_quill/models/documents/nodes/leaf.dart';
import 'editor.dart';
typedef EmbedBuilder = Widget Function(BuildContext context, Embed node);
abstract class EditorTextSelectionGestureDetectorBuilderDelegate {
GlobalKey<EditorState> getEditableTextKey();

@ -54,6 +54,7 @@ class QuillEditor extends StatefulWidget {
final Brightness keyboardAppearance;
final ScrollPhysics scrollPhysics;
final ValueChanged<String> onLaunchUrl;
final EmbedBuilder embedBuilder;
QuillEditor(
this.controller,
@ -71,12 +72,14 @@ class QuillEditor extends StatefulWidget {
this.textCapitalization,
this.keyboardAppearance,
this.scrollPhysics,
this.onLaunchUrl)
this.onLaunchUrl,
this.embedBuilder)
: assert(controller != null),
assert(scrollController != null),
assert(scrollable != null),
assert(autoFocus != null),
assert(readOnly != null);
assert(readOnly != null),
assert(embedBuilder != null);
@override
_QuillEditorState createState() => _QuillEditorState();
@ -175,7 +178,8 @@ class _QuillEditorState extends State<QuillEditor>
textSelectionControls,
widget.keyboardAppearance,
widget.enableInteractiveSelection,
widget.scrollPhysics),
widget.scrollPhysics,
widget.embedBuilder),
);
}
@ -229,6 +233,7 @@ class RawEditor extends StatefulWidget {
final Brightness keyboardAppearance;
final bool enableInteractiveSelection;
final ScrollPhysics scrollPhysics;
final EmbedBuilder embedBuilder;
RawEditor(
Key key,
@ -252,7 +257,8 @@ class RawEditor extends StatefulWidget {
this.selectionCtrls,
this.keyboardAppearance,
this.enableInteractiveSelection,
this.scrollPhysics)
this.scrollPhysics,
this.embedBuilder)
: assert(controller != null),
assert(focusNode != null),
assert(scrollable || scrollController != null),
@ -267,6 +273,7 @@ class RawEditor extends StatefulWidget {
assert(autoFocus != null),
assert(toolbarOptions != null),
showCursor = showCursor ?? !readOnly,
assert(embedBuilder != null),
super(key: key);
@override

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_quill/models/documents/nodes/block.dart';
import 'package:tuple/tuple.dart';
import 'box.dart';
import 'delegate.dart';
class EditableTextBlock extends StatelessWidget {
final Block block;
@ -13,6 +13,7 @@ class EditableTextBlock extends StatelessWidget {
final bool enableInteractiveSelection;
final bool hasFocus;
final EdgeInsets contentPadding;
final EmbedBuilder embedBuilder;
EditableTextBlock(
this.block,
@ -22,7 +23,10 @@ class EditableTextBlock extends StatelessWidget {
this.color,
this.enableInteractiveSelection,
this.hasFocus,
this.contentPadding);
this.contentPadding,
this.embedBuilder)
: assert(hasFocus != null),
assert(embedBuilder != null);
@override
Widget build(BuildContext context) {

@ -4,6 +4,7 @@ import 'package:flutter_quill/models/documents/attribute.dart';
import 'package:flutter_quill/models/documents/nodes/container.dart'
as container;
import 'package:flutter_quill/models/documents/nodes/leaf.dart' as leaf;
import 'package:flutter_quill/models/documents/nodes/leaf.dart';
import 'package:flutter_quill/models/documents/nodes/line.dart';
import 'package:flutter_quill/models/documents/nodes/node.dart';
import 'package:flutter_quill/models/documents/style.dart';
@ -13,20 +14,26 @@ import 'package:tuple/tuple.dart';
import 'box.dart';
import 'default_styles.dart';
import 'delegate.dart';
class TextLine extends StatelessWidget {
final Line line;
final TextDirection textDirection;
final EmbedBuilder embedBuilder;
const TextLine({Key key, this.line, this.textDirection})
const TextLine({Key key, this.line, this.textDirection, this.embedBuilder})
: assert(line != null),
assert(embedBuilder != null),
super(key: key);
@override
Widget build(BuildContext context) {
assert(debugCheckHasMediaQuery(context));
// TODO: line.hasEmbed
if (line.hasEmbed) {
Embed embed = line.children.single as Embed;
return EmbedProxy(embedBuilder(context, embed));
}
TextSpan textSpan = _buildTextSpan(context);
StrutStyle strutStyle =

Loading…
Cancel
Save