Using if statement to show a container in flutter


I have this certain issue so there is a URL in my flutter app where,

String URL = "www.abcd/page=$number";
int number = 1;

And a button with onTap where,

Inkwell(child:Container(child: Text("Next")),
 onTap :()=> setState({

Sorry I typed those codes manually maybe there is some syntax error.
So basically I want the user to tap on the next button the page number in the link increases by 1, but I want to iterate an ‘if’ function, when number> 1 then show a button where the page decrements by one and if number<1 then I don’t want the container to show.

So is there any way to achieve it?


Use a ternary operator

condition ? if True : if False

In your case use it on the on the button that decrements by 1.

number>1 ? shows Button : shows empty Sizedbox

       ? InkWell(
        onTap: (() {
          setState(() {
        child: Container(
          height: 30,
          child: Text('Previous'),
        : SizedBox(),

enter image description here

enter image description here

Answered By – pupil gudang

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published