【问题标题】:how to make Widget attributs optiobal in flutter如何在颤动中使 Widget 属性可选
【发布时间】:2020-06-01 15:40:39
【问题描述】:

如何在颤振中将小部件属性设为可选,例如: 如果widget.image 不是 null 用户图像属性来设置背景,如果它为 null 则使用颜色属性

container(
  BoxDecoration(

         if(widget.image){
           image: AssetImage("images/background/background1.jpg",),fit: BoxFit.cover),
         }
         else {
           color : Colors.white
         }
)

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:
    Container(
      decoration: widget.image!=null ? 
       BoxDecoration(
        image: AssetImage("images/background/background1.jpg",),
        fit: BoxFit.cover
       ):
       BoxDecoration(color : Colors.white)  
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-17
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 2021-11-29
      相关资源
      最近更新 更多