Add super editor
This commit is contained in:
parent
3e2c9406f0
commit
cb007edd27
|
|
@ -307,8 +307,11 @@ class _InvoiceEmailViewState extends State<InvoiceEmailView>
|
||||||
child: Material(
|
child: Material(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
child: ExampleEditor(
|
child: ExampleEditor(
|
||||||
key: ValueKey('__body_${_rawBodyPreview}__'),
|
value: _rawBodyPreview,
|
||||||
initialValue: _rawBodyPreview,
|
onChanged: (value) {
|
||||||
|
_bodyController.text = value;
|
||||||
|
_onChanged();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,12 @@ import 'package:super_editor/super_editor.dart';
|
||||||
class ExampleEditor extends StatefulWidget {
|
class ExampleEditor extends StatefulWidget {
|
||||||
const ExampleEditor({
|
const ExampleEditor({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.initialValue,
|
@required this.value,
|
||||||
|
@required this.onChanged,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final String initialValue;
|
final String value;
|
||||||
|
final Function(String) onChanged;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ExampleEditorState createState() => _ExampleEditorState();
|
_ExampleEditorState createState() => _ExampleEditorState();
|
||||||
|
|
@ -39,12 +41,10 @@ class _ExampleEditorState extends State<ExampleEditor> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
print('## INIT: ${widget.initialValue}');
|
|
||||||
final value = deserializeMarkdownToDocument(widget.initialValue);
|
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_doc = value..addListener(_hideOrShowToolbar);
|
_doc = deserializeMarkdownToDocument(widget.value)
|
||||||
|
..addListener(_hideOrShowToolbar);
|
||||||
_docEditor = DocumentEditor(document: _doc as MutableDocument);
|
_docEditor = DocumentEditor(document: _doc as MutableDocument);
|
||||||
_composer = DocumentComposer()..addListener(_hideOrShowToolbar);
|
_composer = DocumentComposer()..addListener(_hideOrShowToolbar);
|
||||||
_docOps = CommonEditorOperations(
|
_docOps = CommonEditorOperations(
|
||||||
|
|
@ -57,6 +57,16 @@ class _ExampleEditorState extends State<ExampleEditor> {
|
||||||
_scrollController = ScrollController()..addListener(_hideOrShowToolbar);
|
_scrollController = ScrollController()..addListener(_hideOrShowToolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(ExampleEditor oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
|
||||||
|
if (widget.value != oldWidget.value) {
|
||||||
|
_doc = deserializeMarkdownToDocument(widget.value)
|
||||||
|
..addListener(_hideOrShowToolbar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
if (_textFormatBarOverlayEntry != null) {
|
if (_textFormatBarOverlayEntry != null) {
|
||||||
|
|
@ -70,6 +80,9 @@ class _ExampleEditorState extends State<ExampleEditor> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _hideOrShowToolbar() {
|
void _hideOrShowToolbar() {
|
||||||
|
final value = serializeDocumentToMarkdown(_doc);
|
||||||
|
widget.onChanged(value);
|
||||||
|
|
||||||
if (_gestureMode != DocumentGestureMode.mouse) {
|
if (_gestureMode != DocumentGestureMode.mouse) {
|
||||||
// We only add our own toolbar when using mouse. On mobile, a bar
|
// We only add our own toolbar when using mouse. On mobile, a bar
|
||||||
// is rendered for us.
|
// is rendered for us.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue