flutter-quill icon indicating copy to clipboard operation
flutter-quill copied to clipboard

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

Open apleton opened this issue 1 year ago • 6 comments

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
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<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  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
[Paste your logs here]

apleton avatar May 17 '24 07:05 apleton

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

thanglq1 avatar Jun 01 '24 10:06 thanglq1

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.

apleton avatar Jun 01 '24 11:06 apleton

Thanks. I downgraded to version 9.3.5

thanglq1 avatar Jun 01 '24 12:06 thanglq1

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

maxencealluin avatar Jul 15 '24 16:07 maxencealluin

Still have the same issue with latest version 10.4.5.

john-fly avatar Aug 26 '24 01:08 john-fly

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.

complianceexperts avatar Aug 27 '24 23:08 complianceexperts