From 1cf37c1824197f4907cf820705de07cf92c77b2d Mon Sep 17 00:00:00 2001 From: Till Friebe Date: Sat, 27 Mar 2021 18:57:40 +0100 Subject: [PATCH] Rebuild editor when keyboard is already open (#111) * Rebuild editor when keyboard is already open If the keyboard is already open, but the editor thinks that the keyboard is not open, the text will not be updated when writing. This can easily happen if one has a `TabBarView` with two children, each with an `QuillEditor`, see the code for an example:
Example ```dart import 'package:flutter/material.dart'; import 'package:flutter_quill/widgets/controller.dart'; import 'package:flutter_quill/widgets/editor.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { late QuillController _controller1; late QuillController _controller2; @override void initState() { _controller1 = QuillController.basic(); _controller2 = QuillController.basic(); super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: DefaultTabController( length: 2, child: Scaffold( appBar: AppBar( title: Text('Flutter Quill tabs demo'), bottom: TabBar( tabs: [ Tab(text: 'First'), Tab(text: 'Second'), ], ), ), body: TabBarView( children: [ QuillEditor.basic(controller: _controller1, readOnly: false), QuillEditor.basic(controller: _controller2, readOnly: false), ], ), ), ), ); } }
Video
* Add documentation comment for getOffsetToRevealCursor * Set initial keyboard visibility --- lib/widgets/editor.dart | 5 +++++ lib/widgets/raw_editor.dart | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index ef2221c0..0913ffe0 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -864,6 +864,11 @@ class RenderEditor extends RenderEditableContainerBox ); } + /// Returns the y-offset of the editor at which [selection] is visible. + /// + /// The offset is the distance from the top of the editor and is the minimum + /// from the current scroll position until [selection] becomes visible. + /// Returns null if [selection] is already visible. double? getOffsetToRevealCursor( double viewportHeight, double scrollOffset, double offsetInViewport) { List endpoints = getEndpointsForSelection(selection); diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index 11c9c568..73a17e25 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -700,6 +700,7 @@ class RawEditorState extends EditorState _keyboardVisible = true; } else { _keyboardVisibilityController = KeyboardVisibilityController(); + _keyboardVisible = _keyboardVisibilityController!.isVisible; _keyboardVisibilitySubscription = _keyboardVisibilityController?.onChange.listen((bool visible) { _keyboardVisible = visible;