2017-11-07 4 views
3

、コンテナは、詰め物を持っていますFlutter.io(ダーツ) - 左のパディングオーバーライドを作成する方法は?フラッターで

padding: const EdgeInsets.only(
    left: MyMeasurements.globalLeftPadding, 
    right: 20.0, 
), 

私は「左」を上書きできるようにしたいです。

私はこれを行う場合、私はランタイムエラーを取得:

padding: const EdgeInsets.only(
    left: left ?? 14.0, 
    right: 20.0, 
), 

// and in the container that has the override... 
new MySectionHeader(
    left: 12.0, 
), 

提案:

class MySectionHeader extends StatelessWidget { 
    final double left; 

MySectionHeader({ 
    this.left, 
}); 

// down to the widget body 
padding: const EdgeInsets.only(
    left: left ?? MyMeasurements.globalLeftPadding, 
    right: 20.0, 
), 

// and in the container that has the override... 
new MySectionHeader(
    left: 12.0, 
), 

これは、実行時エラーを取得しましたか?

答えて

1

constコンストラクタと動的コンテンツの両方を使用することはできません。 代わりにnew EdgeInsets.only(を実行してください

+0

多くのありがとうございます!!!! – Deborah

関連する問題