【发布时间】:2017-07-27 19:31:14
【问题描述】:
我在执行 Widget 的构造函数时遇到奇怪的运行时错误。
这是课程:
class NumberPicker extends StatefulWidget {
NumberPicker.integer({
Key key,
@required int initialValue,
@required int minValue,
@required int maxValue,
})
: assert(initialValue != null),
assert(minValue != null),
assert(maxValue != null),
assert(maxValue > minValue),
assert(initialValue >= minValue &&
initialValue <= maxValue),
this._internal(
minDoubleValue: -1.0,
maxDoubleValue: -1.0,
initialDoubleValue: -1.0,
decimalPlaces: 0,
minIntValue: minValue,
maxIntValue: maxValue,
initialIntValue: initialValue
);
NumberPicker._internal({
Key key,
@required this.minDoubleValue,
@required this.maxDoubleValue,
@required this.initialDoubleValue,
@required this.decimalPlaces,
@required this.minIntValue,
@required this.maxIntValue,
@required this.initialIntValue,
}) :
super(key: key);
final double minDoubleValue;
final double maxDoubleValue;
final double initialDoubleValue;
final int decimalPlaces;
final int minIntValue;
final int maxIntValue;
final int initialIntValue;
@override
_NumberPickerState createState() => new _NumberPickerState();
}
当我打电话给new NumberPicker.integer(initialValue: 50, minValue: 1, maxValue: 100)时
我收到以下错误:
I/flutter ( 3873): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 3873): The following _CompileTimeError was thrown while handling a gesture:
I/flutter ( 3873): 'package:numberpicker/numberpicker.dart': error: line 20: '=' expected
I/flutter ( 3873): this._internal(
I/flutter ( 3873): ^
值得一提的是代码可以编译,我没有语法错误,但是当我调用构造函数时,我只看到堆栈跟踪:(
谁能向我解释我做错了什么?
【问题讨论】:
-
如果你删除断言它应该工作