forked from memspace/zefyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdc2a62
commit e54be6e
Showing
4 changed files
with
107 additions
and
29 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:quill_delta/quill_delta.dart'; | ||
import 'package:zefyr/zefyr.dart'; | ||
|
||
class EditorPage extends StatefulWidget { | ||
@override | ||
EditorPageState createState() => EditorPageState(); | ||
} | ||
|
||
class EditorPageState extends State<EditorPage> { | ||
/// Allows to control the editor and the document. | ||
ZefyrController _controller; | ||
|
||
/// Zefyr editor like any other input field requires a focus node. | ||
FocusNode _focusNode; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
// Here we must load the document and pass it to Zefyr controller. | ||
final document = _loadDocument(); | ||
_controller = new ZefyrController(document); | ||
_focusNode = new FocusNode(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
// Note that the editor requires special `ZefyrScaffold` widget to be | ||
// present somewhere up the widget tree. | ||
return Scaffold( | ||
appBar: AppBar(title: Text("Editor page")), | ||
body: ZefyrScaffold( | ||
child: ZefyrEditor( | ||
padding: EdgeInsets.all(16), | ||
controller: _controller, | ||
focusNode: _focusNode, | ||
), | ||
), | ||
); | ||
} | ||
|
||
/// Loads the document to be edited in Zefyr. | ||
NotusDocument _loadDocument() { | ||
// For simplicity we hardcode a simple document with one line of text | ||
// saying "Zefyr Quick Start". | ||
final Delta delta = Delta()..insert("Zefyr Quick Start\n"); | ||
// Note that delta must always end with newline. | ||
return NotusDocument.fromDelta(delta); | ||
} | ||
} |