小编Sew*_*wer的帖子

如何在flutter小部件中使用条件语句/三元

我需要知道是否有可能在flutter小部件中使用三元/如果不使用其他语言。

我正在尝试创建一个buttonCreator小部件,该小部件将使用几个参数,其中一个将是背景。我需要检查小部件是否启用了后台。我所拥有的是这个,但是我不知道如何在真实的Dart代码中使用它。

Container buildButton(String text, bool bg){
  return new Container(
    decoration: new BoxDecoration(
      border: new Border.all(color: Colors.white),
      if (bg != true ? color: Colors.white : '')
    ),
    padding: new EdgeInsets.all(15.0),
    margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
    child: new Center(
      child: new Text(
        text, style: new TextStyle(color: Colors.white, fontFamily: 'Monsterrat')
      )
    ),
  );
};
Run Code Online (Sandbox Code Playgroud)

dart flutter

2
推荐指数
1
解决办法
7681
查看次数

标签 统计

dart ×1

flutter ×1