【问题标题】:flutter: why I cannot use the final member field as the padding of widget?颤振:为什么我不能使用最终成员字段作为小部件的填充?
【发布时间】:2018-05-19 12:04:23
【问题描述】:

我写了以下小部件:

class Bottombar extends StatelessWidget {
  final double padding;
  Bottombar({@required this.padding});
  @override
  Widget build(BuildContext context) {
    return new Container(
      padding: const EdgeInsets.all(padding), child: new Text('Test'),);
  }
}

但是,它报告了填充参数必须是常量表达式的编译错误。为什么不能使用最终成员字段作为小部件填充的参数?什么原因?

flutter 版本为 beta 0.3.1

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    问题是您使用const 创建EdgeInsets,但随后传递了一个变量padding

    删除const,它应该可以工作。

    【讨论】:

      猜你喜欢
      • 2021-07-15
      • 2017-10-18
      • 2020-05-24
      • 2019-05-17
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-16
      相关资源
      最近更新 更多