Browse Source

updating quick start

Anatoly Pulyaevskiy 5 years ago
parent
commit
42ff56abb8

BIN
.DS_Store View File


BIN
assets/.DS_Store View File


BIN
assets/quick-start-rec-01.mp4 View File


+ 34
- 15
doc/quick-start.md View File

3
 In this tutorial you'll create a simple Flutter app that supports rich text
3
 In this tutorial you'll create a simple Flutter app that supports rich text
4
 editing with Zefyr. What you'll learn:
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
 * How to load and save documents using JSON serialization
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
 If you haven't installed Flutter yet then [install it first](https://flutter.dev/docs/get-started/install).
12
 If you haven't installed Flutter yet then [install it first](https://flutter.dev/docs/get-started/install).
13
 
13
 
20
 
20
 
21
 For more methods of creating a project see [official documentation](https://flutter.dev/docs/get-started/test-drive).
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
 Add `zefyr` package as a dependency to `pubspec.yaml` of your new project:
25
 Add `zefyr` package as a dependency to `pubspec.yaml` of your new project:
31
 
26
 
34
   zefyr: [latest_version]
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
 We start by creating a `StatefulWidget` that will be responsible for handling
42
 We start by creating a `StatefulWidget` that will be responsible for handling
42
 all the state and interactions with Zefyr. In this example we'll assume
43
 all the state and interactions with Zefyr. In this example we'll assume
74
   @override
75
   @override
75
   Widget build(BuildContext context) {
76
   Widget build(BuildContext context) {
76
     // Note that the editor requires special `ZefyrScaffold` widget to be
77
     // Note that the editor requires special `ZefyrScaffold` widget to be
77
-    // present somewhere up the widget tree.
78
+    // one of its parents.
78
     return Scaffold(
79
     return Scaffold(
79
       appBar: AppBar(title: Text("Editor page")),
80
       appBar: AppBar(title: Text("Editor page")),
80
       body: ZefyrScaffold(
81
       body: ZefyrScaffold(
91
   NotusDocument _loadDocument() {
92
   NotusDocument _loadDocument() {
92
     // For simplicity we hardcode a simple document with one line of text
93
     // For simplicity we hardcode a simple document with one line of text
93
     // saying "Zefyr Quick Start".
94
     // saying "Zefyr Quick Start".
95
+    // (Note that delta must always end with newline.)
94
     final Delta delta = Delta()..insert("Zefyr Quick Start\n");
96
     final Delta delta = Delta()..insert("Zefyr Quick Start\n");
95
-    // Note that delta must always end with newline.
96
     return NotusDocument.fromDelta(delta);
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
 body. We also initialize our editor with a simple one-line document.
103
 body. We also initialize our editor with a simple one-line document.
103
 
104
 
104
 Now we need to wire it up with our app. Open `lib/main.dart` and replace
105
 Now we need to wire it up with our app. Open `lib/main.dart` and replace
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
 Here is how it might look when we run the app and navigate to editor page:
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
 At this point we can already edit the document and apply styles, however if
153
 At this point we can already edit the document and apply styles, however if
135
 we navigate back from this page our changes will be lost. Let's fix this and
154
 we navigate back from this page our changes will be lost. Let's fix this and

+ 1
- 14
packages/zefyr/example/lib/main.dart View File

2
 // for details. All rights reserved. Use of this source code is governed by a
2
 // for details. All rights reserved. Use of this source code is governed by a
3
 // BSD-style license that can be found in the LICENSE file.
3
 // BSD-style license that can be found in the LICENSE file.
4
 import 'package:flutter/material.dart';
4
 import 'package:flutter/material.dart';
5
-
6
 import 'src/form.dart';
5
 import 'src/form.dart';
7
 import 'src/full_page.dart';
6
 import 'src/full_page.dart';
8
-import 'src/quick_start.dart';
9
 import 'src/view.dart';
7
 import 'src/view.dart';
10
 
8
 
11
 void main() {
9
 void main() {
18
     return MaterialApp(
16
     return MaterialApp(
19
       debugShowCheckedModeBanner: false,
17
       debugShowCheckedModeBanner: false,
20
       title: 'Zefyr Editor',
18
       title: 'Zefyr Editor',
21
-//      theme: ThemeData(primarySwatch: Colors.cyan),
19
+      theme: ThemeData(primarySwatch: Colors.cyan),
22
       home: HomePage(),
20
       home: HomePage(),
23
       routes: {
21
       routes: {
24
         "/fullPage": buildFullPage,
22
         "/fullPage": buildFullPage,
25
         "/form": buildFormPage,
23
         "/form": buildFormPage,
26
         "/view": buildViewPage,
24
         "/view": buildViewPage,
27
-        "/quick-start": buildQuickStart,
28
       },
25
       },
29
     );
26
     );
30
   }
27
   }
40
   Widget buildViewPage(BuildContext context) {
37
   Widget buildViewPage(BuildContext context) {
41
     return ViewScreen();
38
     return ViewScreen();
42
   }
39
   }
43
-
44
-  Widget buildQuickStart(BuildContext context) {
45
-    return EditorPage();
46
-  }
47
 }
40
 }
48
 
41
 
49
 class HomePage extends StatelessWidget {
42
 class HomePage extends StatelessWidget {
78
             color: Colors.lightBlue,
71
             color: Colors.lightBlue,
79
             textColor: Colors.white,
72
             textColor: Colors.white,
80
           ),
73
           ),
81
-          FlatButton(
82
-            onPressed: () => nav.pushNamed('/quick-start'),
83
-            child: Text('Quick Start Tutorial'),
84
-            color: Colors.lightBlue,
85
-            textColor: Colors.white,
86
-          ),
87
           Expanded(child: Container()),
74
           Expanded(child: Container()),
88
         ],
75
         ],
89
       ),
76
       ),

+ 39
- 0
packages/zefyr/example/lib/quick_start.dart View File

1
+// Copyright (c) 2018, the Zefyr project authors.  Please see the AUTHORS file
2
+// for details. All rights reserved. Use of this source code is governed by a
3
+// BSD-style license that can be found in the LICENSE file.
4
+import 'package:flutter/material.dart';
5
+
6
+import 'src/editor_page.dart';
7
+
8
+void main() {
9
+  runApp(QuickStartApp());
10
+}
11
+
12
+class QuickStartApp extends StatelessWidget {
13
+  @override
14
+  Widget build(BuildContext context) {
15
+    return MaterialApp(
16
+      title: 'Quick Start',
17
+      home: HomePage(),
18
+      routes: {
19
+        "/editor": (context) => EditorPage(),
20
+      },
21
+    );
22
+  }
23
+}
24
+
25
+class HomePage extends StatelessWidget {
26
+  @override
27
+  Widget build(BuildContext context) {
28
+    final navigator = Navigator.of(context);
29
+    return Scaffold(
30
+      appBar: AppBar(title: Text("Quick Start")),
31
+      body: Center(
32
+        child: FlatButton(
33
+          child: Text("Open editor"),
34
+          onPressed: () => navigator.pushNamed("/editor"),
35
+        ),
36
+      ),
37
+    );
38
+  }
39
+}

packages/zefyr/example/lib/src/quick_start.dart → packages/zefyr/example/lib/src/editor_page.dart View File

56
   NotusDocument _loadDocument() {
56
   NotusDocument _loadDocument() {
57
     // For simplicity we hardcode a simple document with one line of text
57
     // For simplicity we hardcode a simple document with one line of text
58
     // saying "Zefyr Quick Start".
58
     // saying "Zefyr Quick Start".
59
-//    final Delta delta = Delta()..insert("Zefyr Quick Start\n");
60
-    // Note that delta must always end with newline.
61
-//    return NotusDocument.fromDelta(delta);
59
+    final Delta delta = Delta()..insert("Zefyr Quick Start\n");
60
+//     Note that delta must always end with newline.
61
+    return NotusDocument.fromDelta(delta);
62
 
62
 
63
-    final file = File(Directory.systemTemp.path + "/quick_start.json");
64
-    final contents = file.readAsStringSync();
65
-    return NotusDocument.fromJson(jsonDecode(contents));
63
+//    final file = File(Directory.systemTemp.path + "/quick_start.json");
64
+//    final contents = file.readAsStringSync();
65
+//    return NotusDocument.fromJson(jsonDecode(contents));
66
   }
66
   }
67
 
67
 
68
   void _saveDocument(BuildContext context) {
68
   void _saveDocument(BuildContext context) {