Support hr embed

pull/13/head
singerdmx 4 years ago
parent 53557aba58
commit cd88b9d04e
  1. 8
      app/assets/sample_data.json
  2. 28
      app/lib/pages/home_page.dart
  3. 7
      lib/models/documents/attribute.dart

@ -9,7 +9,13 @@
"insert":"\n"
},
{
"insert":"Rich text editor for Flutter"
"insert":{
"_type":"hr",
"_inline":false
}
},
{
"insert":"\nRich text editor for Flutter"
},
{
"attributes":{

@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@ -21,9 +20,6 @@ class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
print(Directory.current.path); // /
_loadFromAssets();
}
@ -91,17 +87,19 @@ class _HomePageState extends State<HomePage> {
}
Widget _embedBuilder(BuildContext context, leaf.Embed node) {
if (node.value.type == 'hr') {
final style = QuillStyles.getStyles(context, true);
return Divider(
height: style.paragraph.style.fontSize * style.paragraph.style.height,
thickness: 2,
color: Colors.grey.shade200,
);
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.');
}
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.');
}
}

@ -54,7 +54,9 @@ class Attribute<T> {
Attribute.italic.key,
Attribute.underline.key,
Attribute.strikeThrough.key,
Attribute.link.key
Attribute.link.key,
Attribute.color.key,
Attribute.background.key
};
static final Set<String> blockKeys = {
@ -84,8 +86,7 @@ class Attribute<T> {
bool get isInline => scope == AttributeScope.INLINE;
bool get isBlockExceptHeader =>
scope == AttributeScope.BLOCK && key != Attribute.header.key;
bool get isBlockExceptHeader => blockKeysExceptHeader.contains(key);
Map<String, dynamic> toJson() => <String, dynamic>{key: value};

Loading…
Cancel
Save