这是我第一次尝试使用 flutter_math_fork 0.7.2 包来显示 Tex 方程式,但由于以下错误("hashValues" is not found or defined
),它甚至无法编译:
flutter run
Launching lib/main.dart on sdk gphone x86 in debug mode...
../../.pub-cache/hosted/pub.dev/flutter_math_fork-0.7.2/lib/src/widgets/selectable.dart:603:23: Error: The method 'hashValues' isn't defined for the class 'SelectionStyle'.
- 'SelectionStyle' is from 'package:flutter_math_fork/src/widgets/selectable.dart' ('../../.pub-cache/hosted/pub.dev/flutter_math_fork-0.7.2/lib/src/widgets/selectable.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hashValues'.
int get hashCode => hashValues(
^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_math_fork-0.7.2/lib/src/ast/options.dart:400:7: Error: The method 'hashValues' isn't defined for the class 'FontOptions'.
- 'FontOptions' is from 'package:flutter_math_fork/src/ast/options.dart' ('../../.pub-cache/hosted/pub.dev/flutter_math_fork-0.7.2/lib/src/ast/options.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hashValues'.
hashValues(fontFamily.hashCode, fontWeight.hashCode, fontShape.hashCode);
^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_math_fork-0.7.2/lib/src/ast/options.dart:434:7: Error: The method 'hashValues' isn't defined for the class 'PartialFontOptions'.
- 'PartialFontOptions' is from 'package:flutter_math_fork/src/ast/options.dart' ('../../.pub-cache/hosted/pub.dev/flutter_math_fork-0.7.2/lib/src/ast/options.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hashValues'.
hashValues(fontFamily.hashCode, fontWeight.hashCode, fontShape.hashCode);
^^^^^^^^^^
Target kernel_snapshot_program failed: Exception
FAILURE: Build failed with an exception.
我的代码:
import 'package:flutter_math_fork/flutter_math.dart';
...
child: choicesContainsTexEquation ? Text(text) : Math.tex(text),
上面的变量text
是从 JSON 文件中读取的。使用下面的两个文本(解码为字符串)时,会出现相同的错误(无论是尝试在 Android 模拟器还是 Chrome 上运行):
"text":"test"
和"text": "e^{i\\pi}+1=0"
在pubspec.yaml
:
dependencies:
flutter:
sdk: flutter
flutter_math_fork: ^0.7.2
可能存在什么问题?
我尝试更改文本(使用 Tex 方程式或“纯”文本)和平台(Android 模拟器和 Chrome),但出现了相同的错误。
问题出在软件包本身。我猜这个软件包最近维护不善,所以可能会发生这样的事情。
我认为,如果您真的依赖此软件包,您唯一能做的就是使用已修复此特定问题的分支。或者创建自己的已修复分支。
我在 GitHub 上搜索了一下,找到了修复您问题的 fork,这里是:https ://github.com/Telosnex/flutter_math_fork_fork.git 特别是,这里是带有修复的提交。
您可以尝试在您的项目中使用它,只需
podspec.yaml
像这样修改游览即可:但是,我认为,创建自己的带有修复的分支是更为可靠的方法。