Ver código fonte

updating quick start

Anatoly Pulyaevskiy 5 anos atrás
pai
commit
42ff56abb8

BIN
.DS_Store Ver arquivo


BIN
assets/.DS_Store Ver arquivo


BIN
assets/quick-start-rec-01.mp4 Ver arquivo


+ 34
- 15
doc/quick-start.md Ver arquivo

@@ -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

+ 1
- 14
packages/zefyr/example/lib/main.dart Ver arquivo

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

+ 39
- 0
packages/zefyr/example/lib/quick_start.dart Ver arquivo

@@ -0,0 +1,39 @@
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 Ver arquivo

@@ -56,13 +56,13 @@ class EditorPageState extends State<EditorPage> {
56 56
   NotusDocument _loadDocument() {
57 57
     // For simplicity we hardcode a simple document with one line of text
58 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 68
   void _saveDocument(BuildContext context) {