|
@@ -0,0 +1,86 @@
|
|
1
|
+import 'package:flutter/material.dart';
|
|
2
|
+
|
|
3
|
+import 'controller.dart';
|
|
4
|
+import 'editor.dart';
|
|
5
|
+import 'image.dart';
|
|
6
|
+import 'toolbar.dart';
|
|
7
|
+
|
|
8
|
+/// Zefyr editor with material design decorations.
|
|
9
|
+class ZefyrField extends StatefulWidget {
|
|
10
|
+ /// Decoration to paint around this editor.
|
|
11
|
+ final InputDecoration decoration;
|
|
12
|
+
|
|
13
|
+ /// Height of this editor field.
|
|
14
|
+ final double height;
|
|
15
|
+ final ZefyrController controller;
|
|
16
|
+ final FocusNode focusNode;
|
|
17
|
+ final bool autofocus;
|
|
18
|
+ final bool enabled;
|
|
19
|
+ final ZefyrToolbarDelegate toolbarDelegate;
|
|
20
|
+ final ZefyrImageDelegate imageDelegate;
|
|
21
|
+ final ScrollPhysics physics;
|
|
22
|
+
|
|
23
|
+ const ZefyrField({
|
|
24
|
+ Key key,
|
|
25
|
+ this.decoration,
|
|
26
|
+ this.height,
|
|
27
|
+ this.controller,
|
|
28
|
+ this.focusNode,
|
|
29
|
+ this.autofocus: false,
|
|
30
|
+ this.enabled,
|
|
31
|
+ this.toolbarDelegate,
|
|
32
|
+ this.imageDelegate,
|
|
33
|
+ this.physics,
|
|
34
|
+ }) : super(key: key);
|
|
35
|
+
|
|
36
|
+ @override
|
|
37
|
+ _ZefyrFieldState createState() => _ZefyrFieldState();
|
|
38
|
+}
|
|
39
|
+
|
|
40
|
+class _ZefyrFieldState extends State<ZefyrField> {
|
|
41
|
+ @override
|
|
42
|
+ Widget build(BuildContext context) {
|
|
43
|
+ Widget child = ZefyrEditor(
|
|
44
|
+ padding: EdgeInsets.symmetric(vertical: 6.0),
|
|
45
|
+ controller: widget.controller,
|
|
46
|
+ focusNode: widget.focusNode,
|
|
47
|
+ autofocus: widget.autofocus,
|
|
48
|
+ enabled: widget.enabled ?? true,
|
|
49
|
+ toolbarDelegate: widget.toolbarDelegate,
|
|
50
|
+ imageDelegate: widget.imageDelegate,
|
|
51
|
+ physics: widget.physics,
|
|
52
|
+ );
|
|
53
|
+
|
|
54
|
+ if (widget.height != null) {
|
|
55
|
+ child = ConstrainedBox(
|
|
56
|
+ constraints: BoxConstraints.tightFor(height: widget.height),
|
|
57
|
+ child: child,
|
|
58
|
+ );
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ return AnimatedBuilder(
|
|
62
|
+ animation:
|
|
63
|
+ Listenable.merge(<Listenable>[widget.focusNode, widget.controller]),
|
|
64
|
+ builder: (BuildContext context, Widget child) {
|
|
65
|
+ return InputDecorator(
|
|
66
|
+ decoration: _getEffectiveDecoration(),
|
|
67
|
+ isFocused: widget.focusNode.hasFocus,
|
|
68
|
+ isEmpty: widget.controller.document.length == 1,
|
|
69
|
+ child: child,
|
|
70
|
+ );
|
|
71
|
+ },
|
|
72
|
+ child: child,
|
|
73
|
+ );
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ InputDecoration _getEffectiveDecoration() {
|
|
77
|
+ final InputDecoration effectiveDecoration =
|
|
78
|
+ (widget.decoration ?? const InputDecoration())
|
|
79
|
+ .applyDefaults(Theme.of(context).inputDecorationTheme)
|
|
80
|
+ .copyWith(
|
|
81
|
+ enabled: widget.enabled ?? true,
|
|
82
|
+ );
|
|
83
|
+
|
|
84
|
+ return effectiveDecoration;
|
|
85
|
+ }
|
|
86
|
+}
|