|
@@ -7,66 +7,81 @@ Zefyr project consists of two packages:
|
7
|
7
|
|
8
|
8
|
### Installation
|
9
|
9
|
|
10
|
|
-Add `zefyr` package as a dependency to your `pubspec.yaml`:
|
|
10
|
+> We assume that you already installed [Flutter](https://flutter.dev/docs/get-started/install) and created a [project](https://flutter.dev/docs/get-started/test-drive).
|
|
11
|
+
|
|
12
|
+Add `zefyr` package as a dependency to `pubspec.yaml` of your project:
|
11
|
13
|
|
12
|
14
|
```yaml
|
13
|
15
|
dependencies:
|
14
|
16
|
zefyr: [latest_version]
|
15
|
17
|
```
|
16
|
18
|
|
17
|
|
-And run `flutter packages get` to install. This installs both `zefyr`
|
18
|
|
-and `notus` packages.
|
|
19
|
+And run `flutter packages get`, this installs both `zefyr` and `notus` packages.
|
19
|
20
|
|
20
|
21
|
### Usage
|
21
|
22
|
|
22
|
|
-There are 4 main objects you would normally interact with in your code:
|
23
|
|
-
|
24
|
|
-* `NotusDocument`, represents a rich text document and provides high-level methods for manipulating the document's state, like inserting, deleting and formatting of text. Read [documentation](concepts/data-and-document.md) for more details on Notus document model and data format.
|
25
|
|
-* `ZefyrEditor`, a Flutter widget responsible for rendering of rich text on the screen and reacting to user actions.
|
26
|
|
-* `ZefyrController`, ties the above two objects together.
|
27
|
|
-* `ZefyrScaffold`, allows embedding Zefyr toolbar into any custom layout.
|
28
|
|
-
|
29
|
|
-Note that `ZefyrEditor` depends on presence of `ZefyrScaffold` somewhere up the
|
30
|
|
-widget tree.
|
31
|
|
-
|
32
|
|
-Normally you would need to place `ZefyrEditor` inside of a
|
33
|
|
-`StatefulWidget`. Shown below is a minimal setup required to use the
|
34
|
|
-editor:
|
|
23
|
+We start by creating a `StatefulWidget` that will be responsible for handling
|
|
24
|
+all the state and interactions with Zefyr. In this example we'll assume
|
|
25
|
+that there is dedicated editor page in our app:
|
35
|
26
|
|
36
|
27
|
```dart
|
37
|
28
|
import 'package:flutter/material.dart';
|
|
29
|
+import 'package:quill_delta/quill_delta.dart';
|
38
|
30
|
import 'package:zefyr/zefyr.dart';
|
39
|
31
|
|
40
|
|
-class MyWidget extends StatefulWidget {
|
|
32
|
+class EditorPage extends StatefulWidget {
|
41
|
33
|
@override
|
42
|
|
- MyWidgetState createState() => MyWidgetState();
|
|
34
|
+ EditorPageState createState() => EditorPageState();
|
43
|
35
|
}
|
44
|
36
|
|
45
|
|
-class MyWidgetState extends State<MyWidget> {
|
|
37
|
+class EditorPageState extends State<EditorPage> {
|
|
38
|
+ /// Allows to control the editor and the document.
|
46
|
39
|
ZefyrController _controller;
|
|
40
|
+
|
|
41
|
+ /// Zefyr editor like any other input field requires a focus node.
|
47
|
42
|
FocusNode _focusNode;
|
48
|
43
|
|
49
|
44
|
@override
|
50
|
45
|
void initState() {
|
51
|
46
|
super.initState();
|
52
|
|
- // Create an empty document or load existing if you have one.
|
53
|
|
- // Here we create an empty document:
|
54
|
|
- final document = new NotusDocument();
|
|
47
|
+ // Here we must load the document and pass it to Zefyr controller.
|
|
48
|
+ final document = _loadDocument();
|
55
|
49
|
_controller = new ZefyrController(document);
|
56
|
50
|
_focusNode = new FocusNode();
|
57
|
51
|
}
|
58
|
52
|
|
59
|
53
|
@override
|
60
|
54
|
Widget build(BuildContext context) {
|
61
|
|
- return ZefyrScaffold(
|
62
|
|
- child: ZefyrEditor(
|
63
|
|
- controller: _controller,
|
64
|
|
- focusNode: _focusNode,
|
|
55
|
+ // Note that the editor requires special `ZefyrScaffold` widget to be
|
|
56
|
+ // present somewhere up the widget tree.
|
|
57
|
+ return Scaffold(
|
|
58
|
+ appBar: AppBar(title: Text("Editor page")),
|
|
59
|
+ body: ZefyrScaffold(
|
|
60
|
+ child: ZefyrEditor(
|
|
61
|
+ padding: EdgeInsets.all(16),
|
|
62
|
+ controller: _controller,
|
|
63
|
+ focusNode: _focusNode,
|
|
64
|
+ ),
|
65
|
65
|
),
|
66
|
66
|
);
|
67
|
67
|
}
|
|
68
|
+
|
|
69
|
+ /// Loads the document to be edited in Zefyr.
|
|
70
|
+ NotusDocument _loadDocument() {
|
|
71
|
+ // For simplicity we hardcode a simple document with one line of text
|
|
72
|
+ // saying "Zefyr Quick Start".
|
|
73
|
+ final Delta delta = Delta()..insert("Zefyr Quick Start\n");
|
|
74
|
+ // Note that delta must always end with newline.
|
|
75
|
+ return NotusDocument.fromDelta(delta);
|
|
76
|
+ }
|
68
|
77
|
}
|
69
|
78
|
```
|
70
|
79
|
|
71
|
|
-This above is required minimum to include Zefyr in your Flutter app and start
|
72
|
|
-writing some rich text.
|
|
80
|
+In the above example we created a page with an AppBar and Zefyr editor in its
|
|
81
|
+body. We also initialize editor with a simple one-line document. Here is how
|
|
82
|
+it might look when we run the app and navigate to editor page:
|
|
83
|
+
|
|
84
|
+<img src="https://github.com/memspace/zefyr/raw/gitbook/assets/quick-start-screen-01.png" width="375">
|
|
85
|
+
|
|
86
|
+At this point we can already edit the document and apply styles, however if
|
|
87
|
+we navigate back from this page our changes will be lost. Let's fix this.
|