Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter duplicate if statement with multiple widgets

Tags:

flutter

dart

Im new to flutter, I see I can't use if statement with curly braces but what if I have the below code, do I have to repeat if statement in every widget?

Block1

    if(product.length>0)
    Container(..)
   
   if(product.length>0)
     Divider(..),

block2

   else
    Container(...)
    Expanded(..)

so I can't use curly here but what is the solution for this issue?

like image 289
Ismail Muhammad Avatar asked Jun 29 '26 22:06

Ismail Muhammad


1 Answers

Use the ...[ block to display multiple widgets conditionally

if(product.length>0) ...[
    Container(..),
    Container(..)
] else ...[
  const SizedBox(),
  Container(..),
]
like image 144
FearlessHyena Avatar answered Jul 02 '26 13:07

FearlessHyena