gpt4 book ai didi

dart - flutter 错误 : Error: Can't access 'this' in a field initializer to read 'computeMaxScale'

转载 作者:IT王子 更新时间:2023-10-29 06:36:35 27 4
gpt4 key购买 nike

<分区>

运行 flutter upgrade 后,我遇到了一些 flutter 问题

我有一个存储 minScalemaxScale 的类。

在构造函数中,我想断言它们之间的间隔。由于这些值可以是 double 值或枚举实例,因此我必须在比较之前计算它们。

构造函数和断言代码:

class ScaleBoundaries {
final dynamic _minScale;
final dynamic _maxScale;
Size size;
ImageInfo imageInfo;

ScaleBoundaries(this._minScale, this._maxScale, { @required this.size, @required this.imageInfo}) :
assert(_minScale is double || _minScale is PhotoViewScaleBoundary),
assert(_maxScale is double || _maxScale is PhotoViewScaleBoundary),
assert(computeMinScale() <= computeMaxScale());

这给了我以下错误:

compiler message: file:///.../photo_view/lib/photo_view_scale_boundaries.dart:14:37: Error: Can't access 'this' in a field initializer to read 'computeMaxScale'.
compiler message: assert(computeMinScale() <= computeMaxScale());
compiler message: ^^^^^^^^^^^^^^^
compiler message: file:///.../photo_view/lib/photo_view_scale_boundaries.dart:14:16: Error: Can't access 'this' in a field initializer to read 'computeMinScale'.
compiler message: assert(computeMinScale() <= computeMaxScale());
compiler message: ^^^^^^^^^^^^^^^

这是我的 flutter doctor 输出:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v0.7.1-pre.15, on Linux, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.1)
✗ Android license status unknown.
[✓] Android Studio (version 3.1)
[✓] IntelliJ IDEA Community Edition (version 2018.1)
[!] VS Code (version 1.25.1)
[✓] Connected devices (1 available)

! Doctor found issues in 2 categories.

我发现的唯一解决方案是删除断言,但那不行。我该如何解决这个问题?

有关详细信息,请参阅整个文件和项目:photo_view_scale_boundaries.dart

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com