singerdmx / flutter-quill

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

Application freezes completely when rapidly switching between multiple QuillEditors #2324

Open bmmshayan opened 1 month ago

bmmshayan commented 1 month ago

Is there an existing issue for this?

Flutter Quill version

10.8.4

Steps to reproduce

  1. Create a ListView with multiple QuillEditor instances.
  2. Rapidly switch focus between these editors, particularly during typing. The issue occurs intermittently, often at the moment of typing.

Expected results

The application should handle rapid focus switches smoothly without freezing, and it should not affect the responsiveness of the system keyboard.

Actual results

The application completely freezes when rapidly switching between QuillEditor instances, requiring a force close of the app. Furthermore, the system keyboard remains unresponsive for about a minute after the application is closed, affecting the usability of other apps.

Additional Context

Minimal Reproducible Code ```dart import 'package:flutter/material.dart'; import 'package:flutter_quill/flutter_quill.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp(home: MyHomePage()); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { late List _controllers; @override void initState() { super.initState(); _controllers = List.generate(5, (_) => QuillController.basic()); } @override Widget build(BuildContext context) { return Scaffold( body: ListView.builder( itemCount: _controllers.length, itemBuilder: (context, index) { return Padding( padding: const EdgeInsets.all(8.0), child: QuillEditor.basic( controller: _controllers[index], scrollController: ScrollController(), configurations: const QuillEditorConfigurations( placeholder: 'Enter text here...', padding: EdgeInsets.symmetric(vertical: 4), ), ), ); }, ), ); } } ```
Logs ```console D/InputMethodManagerUtils(32218): startInputInner - Id : 0 I/InputMethodManager(32218): startInputInner - IInputMethodManagerGlobalInvoker.startInputOrWindowGainedFocus I/InputMethodManager_LC(32218): showSoftInput(View,I) I/ImeTracker(32218): com.testquill.untitled:4b572492: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT I/InputMethodManager_LC(32218): ssi(): flags=0 view=com.testquill.untitled reason = SHOW_SOFT_INPUT I/InputMethodManager_LC(32218): ssi() view is not EditText D/InputMethodManager(32218): showSoftInput() view=io.flutter.embedding.android.FlutterView{4ba62a6 VFE...... .F...... 0,0-1080,2273 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT D/InputMethodManagerUtils(32218): startInputInner - Id : 0 I/InputMethodManager(32218): startInputInner - IInputMethodManagerGlobalInvoker.startInputOrWindowGainedFocus I/InputMethodManager_LC(32218): showSoftInput(View,I) I/ImeTracker(32218): com.testquill.untitled:4a13bf1e: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT I/InputMethodManager_LC(32218): ssi(): flags=0 view=com.testquill.untitled reason = SHOW_SOFT_INPUT I/InputMethodManager_LC(32218): ssi() view is not EditText D/InputMethodManager(32218): showSoftInput() view=io.flutter.embedding.android.FlutterView{4ba62a6 VFE...... .F...... 0,0-1080,2273 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT D/InputMethodManagerUtils(32218): startInputInner - Id : 0 I/InputMethodManager(32218): startInputInner - IInputMethodManagerGlobalInvoker.startInputOrWindowGainedFocus I/InputMethodManager_LC(32218): showSoftInput(View,I) I/ImeTracker(32218): com.testquill.untitled:27660ef0: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT I/InputMethodManager_LC(32218): ssi(): flags=0 view=com.testquill.untitled reason = SHOW_SOFT_INPUT I/InputMethodManager_LC(32218): ssi() view is not EditText D/InputMethodManager(32218): showSoftInput() view=io.flutter.embedding.android.FlutterView{4ba62a6 VFE...... .F...... 0,0-1080,2273 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT ... infinity ... ```
Flutter doctor ```console [√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [Version 10.0.22631.4317], locale ru-UA) • Flutter version 3.24.3 on channel stable at C:\Flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 2663184aa7 (5 weeks ago), 2024-09-11 16:27:48 -0500 • Engine revision 36335019a8 • Dart version 3.5.3 • DevTools version 2.37.3 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\MainUser\AppData\Local\Android\sdk • Platform android-35, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314) • All Android licenses accepted. [X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.3) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.9.34701.34 • Windows 10 SDK version 10.0.22621.0 [√] Android Studio (version 2024.1) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314) [√] VS Code (version 1.92.1) • VS Code at C:\Users\MainUser\AppData\Local\Programs\Microsoft VS Code • Flutter extension can be installed from: https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [√] Connected device (2 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.4317] • Edge (web) • edge • web-javascript • Microsoft Edge 129.0.2792.89 [√] Network resources • All expected network resources are available. ```
EchoEllet commented 1 month ago

Thank you for the report, was this an issue before 10.8.4? Can you try version 10.7.7 to confirm if the issue exists?

bmmshayan commented 1 month ago

@EchoEllet, Thank you for the quick response. I've checked versions 10.7.7 and 9.6.0 on both real devices and emulators, and unfortunately, the issue persists in both. Additionally, I found mentions in some older issues reported by other users that suggest similar problems, albeit in different contexts but essentially the same issue.

EchoEllet commented 1 month ago

Thanks for the check, I assumed there is a possibility that somehow it's related to #2230, though it's very unlikely.

I don't think the editor widget is optimized and designed to work in a ListView with multiple editor widgets.

There's a small possibility that it will be fixed in 11.0.0 or at least improved.

If it's a performance issue with the editor itself and using multiple editors to show it more, then it should be a high priority issue. Otherwise, we're trying to fix other issues, and I'm still uncertain how can we improve it.

You can use Flutter dev tools for debugging performance issues to identify it.

https://docs.flutter.dev/tools/devtools/performance

https://docs.flutter.dev/perf/ui-performance

https://docs.flutter.dev/perf/best-practices

bmmshayan commented 1 month ago

During my experiments, I discovered the following: using FocusNode with a listener setup via focusNode.addListener(() => print('focus[$index]: ${focusNode.hasFocus}')), I observed that during moments of application freezing, the console cyclically outputs the focus status of the last two fields the field being exited and the field being entered. This suggests a potential issue with focus "hanging" between these fields, leading to input management problems.

Perhaps this detail can spark some insight or lead to a potential solution. Thank you for your attention to this matter!