简体   繁体   中英

how to make Widget attributs optiobal in flutter

How can I make widget property as optional in flutter for example: if widget.image is not null user image property to set background and if it null use color property

container(
  BoxDecoration(

         if(widget.image){
           image: AssetImage("images/background/background1.jpg",),fit: BoxFit.cover),
         }
         else {
           color : Colors.white
         }
)
Container(
  decoration: widget.image!=null ? 
   BoxDecoration(
    image: AssetImage("images/background/background1.jpg",),
    fit: BoxFit.cover
   ):
   BoxDecoration(color : Colors.white)  
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM