Update README.md

pull/1444/head
Ahmed Hnewa 2 years ago
parent 4c1ec373b2
commit e4916cfc86
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 8
      README.md
  2. 24
      example/lib/pages/home_page.dart

@ -53,21 +53,25 @@ QuillController _controller = QuillController.basic();
and then embed the toolbar and the editor, within your app. For example: and then embed the toolbar and the editor, within your app. For example:
```dart ```dart
Column( QuillProvider(
configurations: QuillConfigurations(controller: _controller),
child: Column(
children: [ children: [
QuillToolbar.basic(controller: _controller), QuillToolbar.basic(controller: _controller),
Expanded( Expanded(
child: Container( child: Container(
child: QuillEditor.basic( child: QuillEditor.basic(
controller: _controller,
readOnly: false, // true for view only mode readOnly: false, // true for view only mode
), ),
), ),
) )
], ],
),
) )
``` ```
And depending on your use case, you might want to dispose the `_controller` in dispose mehtod
Check out [Sample Page] for advanced usage. Check out [Sample Page] for advanced usage.
## Input / Output ## Input / Output

@ -30,7 +30,7 @@ class HomePage extends StatefulWidget {
} }
class _HomePageState extends State<HomePage> { class _HomePageState extends State<HomePage> {
QuillController? _controller; late final QuillController _controller;
final FocusNode _focusNode = FocusNode(); final FocusNode _focusNode = FocusNode();
Timer? _selectAllTimer; Timer? _selectAllTimer;
_SelectionType _selectionType = _SelectionType.none; _SelectionType _selectionType = _SelectionType.none;
@ -38,6 +38,8 @@ class _HomePageState extends State<HomePage> {
@override @override
void dispose() { void dispose() {
_selectAllTimer?.cancel(); _selectAllTimer?.cancel();
// Dispose the controller to free resources
_controller.dispose();
super.dispose(); super.dispose();
} }
@ -55,7 +57,9 @@ class _HomePageState extends State<HomePage> {
final doc = Document.fromJson(jsonDecode(result)); final doc = Document.fromJson(jsonDecode(result));
setState(() { setState(() {
_controller = QuillController( _controller = QuillController(
document: doc, selection: const TextSelection.collapsed(offset: 0)); document: doc,
selection: const TextSelection.collapsed(offset: 0),
);
}); });
} catch (error) { } catch (error) {
final doc = Document()..insert(0, 'Empty asset'); final doc = Document()..insert(0, 'Empty asset');
@ -85,7 +89,7 @@ class _HomePageState extends State<HomePage> {
actions: [ actions: [
IconButton( IconButton(
onPressed: () => _insertTimeStamp( onPressed: () => _insertTimeStamp(
_controller!, _controller,
DateTime.now().toString(), DateTime.now().toString(),
), ),
icon: const Icon(Icons.add_alarm_rounded), icon: const Icon(Icons.add_alarm_rounded),
@ -94,7 +98,7 @@ class _HomePageState extends State<HomePage> {
onPressed: () => showDialog( onPressed: () => showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
content: Text(_controller!.document.toPlainText([ content: Text(_controller.document.toPlainText([
...FlutterQuillEmbeds.builders(), ...FlutterQuillEmbeds.builders(),
TimeStampEmbedBuilderWidget() TimeStampEmbedBuilderWidget()
])), ])),
@ -115,7 +119,7 @@ class _HomePageState extends State<HomePage> {
} }
bool _onTripleClickSelection() { bool _onTripleClickSelection() {
final controller = _controller!; final controller = _controller;
_selectAllTimer?.cancel(); _selectAllTimer?.cancel();
_selectAllTimer = null; _selectAllTimer = null;
@ -317,11 +321,11 @@ class _HomePageState extends State<HomePage> {
return SafeArea( return SafeArea(
child: QuillProvider( child: QuillProvider(
configurations: QuillConfigurations( configurations: QuillConfigurations(
controller: _controller ?? // (throw ArgumentError.checkNotNull(
(throw ArgumentError.checkNotNull( // _controller,
_controller, // 'Quill controller',
'Quill controller', // ))
)), controller: _controller,
), ),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,

Loading…
Cancel
Save