2017-07-27 8 views
0

私のウィジェットのコンストラクタの実行中に奇妙なランタイムエラーが発生しています。ここでダーツ内部コンストラクタ

クラスです:

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):    ^

は、コードをコンパイルし、私はに関するエラーを持っていないということです私が見るコンストラクタを呼び出すときは、stacktrace :(

誰も私が間違っていることを私に説明することはできますか?

+0

アサートを削除すると、動作するはずです – rkj

答えて

1

クラスの別のコンストラクタを呼び出す場合は、NumberPicker.integerの工場コンストラクタを使用する必要がありますが、アナライザからエラーが発生しない理由はわかりません。

factory 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); 

    return new NumberPicker._internal(
     minDoubleValue: -1.0, 
     maxDoubleValue: -1.0, 
     initialDoubleValue: -1.0, 
     decimalPlaces: 0, 
     minIntValue: minValue, 
     maxIntValue: maxValue, 
     initialIntValue: initialValue 
); 
} 
+0

ありがとうございました!それはそれだった。 :) –

関連する問題