singerdmx / flutter-quill

Rich text editor for Flutter
https://pub.dev/packages/flutter_quill
MIT License
2.6k stars 841 forks source link

[android] assigning a new Document to QuillController causes the keyboard to appear #1870

Open apleton opened 6 months ago

apleton commented 6 months ago

Is there an existing issue for this?

Flutter Quill version

9.3.11 (edit : still there in 9.3.21)

Steps to reproduce

On Android (but not iOS), assigning a new Document object to the class member QuillController.document after the creation of the QuillEditor will cause the widget to gain focus and the soft keyboard to appear. I would like to load text when the user is taping a button, but this bug is preventing me from doing so.

Expected results

QuillEditor does not get the focus and the keyboard does not appear.

Actual results

QuillEditor get the focus and the keyboard appears.

Code sample

Code sample ```dart import 'package:flutter/material.dart'; import 'package:flutter_quill/flutter_quill.dart' as quill; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Quill Test', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { final quill.QuillController _quillController = quill.QuillController.basic(); final FocusNode _editorFocusNode = FocusNode(); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: quill.QuillEditor( focusNode: _editorFocusNode, scrollController: ScrollController(), configurations: quill.QuillEditorConfigurations( placeholder: "Tap to add a comment", controller: _quillController, expands: false, padding: EdgeInsets.zero, ) ), ), floatingActionButton: FloatingActionButton( onPressed: (){ _quillController.document = quill.Document(); // error: will make the keyboard appear!! }, child: const Text("Load"), ), ); } } ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console [Paste your logs here] ```
thanglq1 commented 6 months ago

Hi @apleton . Do you have any solution to fix it or any workaround?

apleton commented 6 months ago

The issue is still there in 9.3.21. As a workaround I create a new QuillController each time I want to load a document.

thanglq1 commented 6 months ago

Thanks. I downgraded to version 9.3.5

maxencealluin commented 4 months ago

Any update on this ? @apleton workaround works but a fix would be appreciated.

john-fly commented 3 months ago

Still have the same issue with latest version 10.4.5.

complianceexperts commented 3 months ago

We are having the same issue, and @apleton workaround works for us. However there are many scenarios we don't want to create new QuillController each time, so a fix would be appreciated.