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

Flutter项目编译失败求助:flutter_math_fork包存在未定义getter错误

解决flutter_math_fork-0.5.0编译错误:GreenNode无optionsDiff getter

问题详情

从Git克隆项目后执行flutter run时编译失败,错误源于flutter_math_fork-0.5.0包的frac.dart文件,提示GreenNode类未定义optionsDiff getter。已尝试flutter pub get和flutter clean,问题仍存在,但其他Flutter项目可正常运行。具体报错:

../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/encoder/tex/functions/frac.dart:113:37: Error: The getter 'optionsDiff' isn't defined for the class 'GreenNode'.
 - 'GreenNode' is from 'package:flutter_math_fork/src/ast/syntax_tree.dart' ('../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/ast/syntax_tree.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'optionsDiff'.
      final remainingOptions = node.optionsDiff.removeStyle();
                                    ^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/encoder/tex/functions/frac.dart:138:37: Error: The getter 'optionsDiff' isn't defined for the class 'GreenNode'.
 - 'GreenNode' is from 'package:flutter_math_fork/src/ast/syntax_tree.dart' ('../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/ast/syntax_tree.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'optionsDiff'.
      final remainingOptions = node.optionsDiff.removeStyle();
                                    ^^^^^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script 'C:\SRC\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1151

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDevDebug'.
> Process 'command 'C:\SRC\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Running Gradle task 'assembleDebug'...                              9.6s
Exception: Gradle task assembleDebug failed with exit code 1

解决方法

  • 指定兼容版本:打开项目的pubspec.yaml,将flutter_math_fork的依赖从^0.5.0改为稳定的旧版本,比如0.4.6,然后执行flutter pub get。示例:

    dependencies:
      flutter_math_fork: 0.4.6
    
  • 依赖修复后的分支:如果需要使用0.5.x系列版本,可直接依赖GitHub上修复该问题的分支(需确认分支存在),修改pubspec.yaml如下,再执行flutter pub get:

    dependencies:
      flutter_math_fork:
        git:
          url: https://github.com/FlutterMath/flutter_math_fork.git
          ref: fix-optionsdiff-error # 替换为实际修复分支名或commit哈希
    
  • 强制覆盖版本(处理依赖冲突):若其他依赖间接引入了冲突版本,在pubspec.yaml中添加dependency_overrides强制指定兼容版本:

    dependency_overrides:
      flutter_math_fork: 0.4.6
    

    执行flutter pub get后重新编译。

  • 临时手动修复(不推荐):找到本地缓存的flutter_math_fork-0.5.0包路径,打开src/ast/syntax_tree.dart,为GreenNode类添加optionsDiff getter,或修改frac.dart中的调用为现有属性(比如检查是否有options属性,替换node.optionsDiff为node.options)。注意此方法会在下次pub get时被覆盖,仅作临时应急。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 04:00:26