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:

<details><summary>Example</summary>

```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<MyApp> {
  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),
            ],
          ),
        ),
      ),
    );
  }
}

</details>

<details><summary>Video</summary>

</details>

* Add documentation comment for getOffsetToRevealCursor

* Set initial keyboard visibility
pull/116/head^2
Till Friebe 4 years ago committed by GitHub
parent ace4fd4deb
commit 1cf37c1824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      lib/widgets/editor.dart
  2. 1
      lib/widgets/raw_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<TextSelectionPoint> endpoints = getEndpointsForSelection(selection);

@ -700,6 +700,7 @@ class RawEditorState extends EditorState
_keyboardVisible = true;
} else {
_keyboardVisibilityController = KeyboardVisibilityController();
_keyboardVisible = _keyboardVisibilityController!.isVisible;
_keyboardVisibilitySubscription =
_keyboardVisibilityController?.onChange.listen((bool visible) {
_keyboardVisible = visible;

Loading…
Cancel
Save