From e4916cfc8622ead2e185407f07228dfdc91d4a0b Mon Sep 17 00:00:00 2001 From: Ahmed Hnewa <73608287+freshtechtips@users.noreply.github.com> Date: Sat, 21 Oct 2023 00:49:16 +0300 Subject: [PATCH] Update README.md --- README.md | 8 ++++++-- example/lib/pages/home_page.dart | 24 ++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8cf38506..5b9c4762 100644 --- a/README.md +++ b/README.md @@ -53,21 +53,25 @@ QuillController _controller = QuillController.basic(); and then embed the toolbar and the editor, within your app. For example: ```dart -Column( +QuillProvider( + configurations: QuillConfigurations(controller: _controller), + child: Column( children: [ QuillToolbar.basic(controller: _controller), Expanded( child: Container( child: QuillEditor.basic( - controller: _controller, 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. ## Input / Output diff --git a/example/lib/pages/home_page.dart b/example/lib/pages/home_page.dart index 29adb93b..29fd7ea1 100644 --- a/example/lib/pages/home_page.dart +++ b/example/lib/pages/home_page.dart @@ -30,7 +30,7 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - QuillController? _controller; + late final QuillController _controller; final FocusNode _focusNode = FocusNode(); Timer? _selectAllTimer; _SelectionType _selectionType = _SelectionType.none; @@ -38,6 +38,8 @@ class _HomePageState extends State { @override void dispose() { _selectAllTimer?.cancel(); + // Dispose the controller to free resources + _controller.dispose(); super.dispose(); } @@ -55,7 +57,9 @@ class _HomePageState extends State { final doc = Document.fromJson(jsonDecode(result)); setState(() { _controller = QuillController( - document: doc, selection: const TextSelection.collapsed(offset: 0)); + document: doc, + selection: const TextSelection.collapsed(offset: 0), + ); }); } catch (error) { final doc = Document()..insert(0, 'Empty asset'); @@ -85,7 +89,7 @@ class _HomePageState extends State { actions: [ IconButton( onPressed: () => _insertTimeStamp( - _controller!, + _controller, DateTime.now().toString(), ), icon: const Icon(Icons.add_alarm_rounded), @@ -94,7 +98,7 @@ class _HomePageState extends State { onPressed: () => showDialog( context: context, builder: (context) => AlertDialog( - content: Text(_controller!.document.toPlainText([ + content: Text(_controller.document.toPlainText([ ...FlutterQuillEmbeds.builders(), TimeStampEmbedBuilderWidget() ])), @@ -115,7 +119,7 @@ class _HomePageState extends State { } bool _onTripleClickSelection() { - final controller = _controller!; + final controller = _controller; _selectAllTimer?.cancel(); _selectAllTimer = null; @@ -317,11 +321,11 @@ class _HomePageState extends State { return SafeArea( child: QuillProvider( configurations: QuillConfigurations( - controller: _controller ?? - (throw ArgumentError.checkNotNull( - _controller, - 'Quill controller', - )), + // (throw ArgumentError.checkNotNull( + // _controller, + // 'Quill controller', + // )) + controller: _controller, ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween,