|
@@ -3,11 +3,11 @@
|
3
|
3
|
In this tutorial you'll create a simple Flutter app that supports rich text
|
4
|
4
|
editing with Zefyr. What you'll learn:
|
5
|
5
|
|
6
|
|
-* How to create a new screen with Zefyr editor
|
7
|
|
-* Basic widget layout required by Zefyr editor
|
|
6
|
+* How to create a new screen for the editor
|
|
7
|
+* Basic widget layout required by Zefyr
|
8
|
8
|
* How to load and save documents using JSON serialization
|
9
|
9
|
|
10
|
|
-### Create a project
|
|
10
|
+### 01. Create a new Flutter project
|
11
|
11
|
|
12
|
12
|
If you haven't installed Flutter yet then [install it first](https://flutter.dev/docs/get-started/install).
|
13
|
13
|
|
|
@@ -20,12 +20,7 @@ $ cd myapp
|
20
|
20
|
|
21
|
21
|
For more methods of creating a project see [official documentation](https://flutter.dev/docs/get-started/test-drive).
|
22
|
22
|
|
23
|
|
-### Add Zefyr to your project
|
24
|
|
-
|
25
|
|
-Zefyr consists of two packages:
|
26
|
|
-
|
27
|
|
-1. [zefyr](https://pub.dev/packages/zefyr) - Flutter package which provides all necessary UI widgets
|
28
|
|
-2. [notus](https://pub.dev/packages/notus) - package containing document model used by `zefyr` package. `notus` package is platform-agnostic and can be used outside of Flutter apps (web or server-side Dart projects).
|
|
23
|
+### 02. Add Zefyr to your new project
|
29
|
24
|
|
30
|
25
|
Add `zefyr` package as a dependency to `pubspec.yaml` of your new project:
|
31
|
26
|
|
|
@@ -34,9 +29,15 @@ dependencies:
|
34
|
29
|
zefyr: [latest_version]
|
35
|
30
|
```
|
36
|
31
|
|
37
|
|
-And run `flutter packages get`, this installs both `zefyr` and `notus` packages.
|
|
32
|
+And run `flutter packages get`.
|
|
33
|
+This installs [zefyr](https://pub.dev/packages/zefyr) and all required
|
|
34
|
+dependencies, including [notus](https://pub.dev/packages/notus) package which
|
|
35
|
+implements Zefyr's document model.
|
38
|
36
|
|
39
|
|
-### Create editor page
|
|
37
|
+> Notus package is platform-agnostic and can be used outside of Flutter apps,
|
|
38
|
+> that is, on the web or server-side.
|
|
39
|
+
|
|
40
|
+### 03. Create editor page
|
40
|
41
|
|
41
|
42
|
We start by creating a `StatefulWidget` that will be responsible for handling
|
42
|
43
|
all the state and interactions with Zefyr. In this example we'll assume
|
|
@@ -74,7 +75,7 @@ class EditorPageState extends State<EditorPage> {
|
74
|
75
|
@override
|
75
|
76
|
Widget build(BuildContext context) {
|
76
|
77
|
// Note that the editor requires special `ZefyrScaffold` widget to be
|
77
|
|
- // present somewhere up the widget tree.
|
|
78
|
+ // one of its parents.
|
78
|
79
|
return Scaffold(
|
79
|
80
|
appBar: AppBar(title: Text("Editor page")),
|
80
|
81
|
body: ZefyrScaffold(
|
|
@@ -91,14 +92,14 @@ class EditorPageState extends State<EditorPage> {
|
91
|
92
|
NotusDocument _loadDocument() {
|
92
|
93
|
// For simplicity we hardcode a simple document with one line of text
|
93
|
94
|
// saying "Zefyr Quick Start".
|
|
95
|
+ // (Note that delta must always end with newline.)
|
94
|
96
|
final Delta delta = Delta()..insert("Zefyr Quick Start\n");
|
95
|
|
- // Note that delta must always end with newline.
|
96
|
97
|
return NotusDocument.fromDelta(delta);
|
97
|
98
|
}
|
98
|
99
|
}
|
99
|
100
|
```
|
100
|
101
|
|
101
|
|
-In the above example we created a page with an AppBar and Zefyr editor in its
|
|
102
|
+Above example widget creates a page with an `AppBar` and Zefyr editor in its
|
102
|
103
|
body. We also initialize our editor with a simple one-line document.
|
103
|
104
|
|
104
|
105
|
Now we need to wire it up with our app. Open `lib/main.dart` and replace
|
|
@@ -125,11 +126,29 @@ class QuickStartApp extends StatelessWidget {
|
125
|
126
|
);
|
126
|
127
|
}
|
127
|
128
|
}
|
|
129
|
+
|
|
130
|
+class HomePage extends StatelessWidget {
|
|
131
|
+ @override
|
|
132
|
+ Widget build(BuildContext context) {
|
|
133
|
+ final navigator = Navigator.of(context);
|
|
134
|
+ return Scaffold(
|
|
135
|
+ appBar: AppBar(title: Text("Quick Start")),
|
|
136
|
+ body: Center(
|
|
137
|
+ child: FlatButton(
|
|
138
|
+ child: Text("Open editor"),
|
|
139
|
+ onPressed: () => navigator.pushNamed("/editor"),
|
|
140
|
+ ),
|
|
141
|
+ ),
|
|
142
|
+ );
|
|
143
|
+ }
|
|
144
|
+}
|
128
|
145
|
```
|
129
|
146
|
|
130
|
147
|
Here is how it might look when we run the app and navigate to editor page:
|
131
|
148
|
|
132
|
|
-<img src="https://github.com/memspace/zefyr/raw/gitbook/assets/quick-start-screen-01.png" width="375">
|
|
149
|
+<video width="600" src="https://github.com/memspace/zefyr/raw/gitbook/assets/quick-start-rec-01.mp4" type="video/mp4" loop>
|
|
150
|
+ Your browser does not support the video tag.
|
|
151
|
+</video>
|
133
|
152
|
|
134
|
153
|
At this point we can already edit the document and apply styles, however if
|
135
|
154
|
we navigate back from this page our changes will be lost. Let's fix this and
|