You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目使用quill编辑器v6.4.2运行报错求助

Flutter 3.3.10 搭配 flutter_quill 6.4.2 编译错误解决方法

环境信息

  • Flutter SDK: 3.3.10
  • Dart: 2.18.6
  • flutter_quill: 6.4.2

编译错误详情

Launching lib\main.dart on Chrome in debug mode...
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:308:8: Error: Type 'ContextMenuButtonItem' not found.
  List<ContextMenuButtonItem> get contextMenuButtonItems {
       ^^^^^^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:327:3: Error: Type 'TextSelectionToolbarAnchors' not found.
  TextSelectionToolbarAnchors get contextMenuAnchors {
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:1516:7: Error: Type 'TextInputControl' not found.
      TextInputControl? oldControl, TextInputControl? newControl) {
      ^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:1516:37: Error: Type 'TextInputControl' not found.
      TextInputControl? oldControl, TextInputControl? newControl) {
                                    ^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:125:12: Error: Undefined name 'AdaptiveTextSelectionToolbar'.
    return AdaptiveTextSelectionToolbar.buttonItems(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:309:25: Error: Member not found: 'EditableText.getEditableButtonItems'.        
    return EditableText.getEditableButtonItems(
                        ^^^^^^^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:331:12: Error: The getter 'TextSelectionToolbarAnchors' isn't defined for the  
class 'RawEditorState'.
 - 'RawEditorState' is from 'package:flutter_quill/src/widgets/raw_editor.dart'
 ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'TextSelectionToolbarAnchors'.
    return TextSelectionToolbarAnchors.fromSelection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:1516:7: Error: 'TextInputControl' isn't a type.
      TextInputControl? oldControl, TextInputControl? newControl) {
      ^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:1516:37: Error: 'TextInputControl' isn't a type.
      TextInputControl? oldControl, TextInputControl? newControl) {
                                    ^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:1522:20: Error: The method 'intentForMacOSSelector' isn't defined for the class
'RawEditorState'.
 - 'RawEditorState' is from 'package:flutter_quill/src/widgets/raw_editor.dart'
 ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart').
Try correcting the name to the name of an existing method, or defining a method named 'intentForMacOSSelector'.
    final intent = intentForMacOSSelector(selectorName);
                   ^^^^^^^^^^^^^^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/raw_editor.dart:1527:17: Error: Inferred type argument 'dynamic' doesn't conform to the bound
'Intent' of the type variable 'T' on 'Actions.invoke'.
 - 'Intent' is from 'package:flutter/src/widgets/actions.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/actions.dart').
 - 'Actions' is from 'package:flutter/src/widgets/actions.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/actions.dart').
Try specifying type arguments explicitly so that they conform to the bounds.
        Actions.invoke(primaryContext, intent);
                ^
/C:/flutter/packages/flutter/lib/src/widgets/actions.dart:860:25: Context: This is the type variable whose bound isn't conformed to.
  static Object? invoke<T extends Intent>(
                        ^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/text_selection.dart:228:10: Error: Method 'insert' cannot be called on 'OverlayState?' because 
it is potentially null.
 - 'OverlayState' is from 'package:flutter/src/widgets/overlay.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/overlay.dart').
Try calling using ?. instead.
        .insert(toolbar!);
         ^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/text_selection.dart:354:10: Error: Method 'insertAll' cannot be called on 'OverlayState?'      
because it is potentially null.
 - 'OverlayState' is from 'package:flutter/src/widgets/overlay.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/overlay.dart').
Try calling using ?. instead.
        .insertAll(_handles!);
         ^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/toolbar/quill_font_family_button.dart:112:41: Error: Property 'context' cannot be accessed on  
'OverlayState?' because it is potentially null.
 - 'OverlayState' is from 'package:flutter/src/widgets/overlay.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/overlay.dart').
Try accessing using ?. instead.
    final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
                                        ^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_quill-6.4.2/lib/src/widgets/toolbar/quill_font_size_button.dart:113:41: Error: Property 'context' cannot be accessed on    
'OverlayState?' because it is potentially null.
 - 'OverlayState' is from 'package:flutter/src/widgets/overlay.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/overlay.dart').
Try accessing using ?. instead.
    final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
            

                         ^^^^^^^

问题根源

flutter_quill 6.x+版本依赖Flutter 3.10及以上版本引入的新API(比如ContextMenuButtonItem、AdaptiveTextSelectionToolbar),而你用的Flutter 3.3.10是旧版本,没有这些API,导致编译报错。

解决方法

方案1:升级Flutter SDK到兼容版本

这是最彻底的解决方式,后续也能避免其他依赖的兼容问题:

  1. 打开终端执行:
    flutter upgrade
    
    或者指定一个稳定的兼容版本(比如3.10.0):
    flutter downgrade 3.10.0
    
  2. 升级完成后,执行:
    flutter clean
    flutter pub get
    

方案2:使用和Flutter 3.3.10兼容的flutter_quill版本

如果不想升级Flutter,就降级flutter_quill到适配旧版本的分支,比如5.x系列:

  1. 修改pubspec.yaml里的依赖:
    flutter_quill: ^5.2.10
    
  2. 清理缓存并重新拉取依赖:
    flutter pub cache clean
    flutter clean
    flutter pub get
    

额外注意事项

  • 不要随意混合不同版本的依赖,每次修改版本后务必执行flutter clean和flutter pub get
  • Flutter和Dart版本是绑定的,升级Flutter后Dart会自动同步到对应版本,不用手动修改

内容的提问来源于stack exchange,提问作者Subham Mahanty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 13:30:54