skip to Main Content

how can I change the container from
this

To this

I tried putting a turnery condition but it says

error: A value of type ‘Row’ can’t be assigned to a variable of type
‘bool’.

Please let me know what I should do..

2

Answers


  1. based on this error I’d assume you try to get your if statement incorrectly somewhere in the build method. I’d advise you to use a function returning widget based on the onTap as you’re saying.

        Widget _dynamicAddButton() {
         if(clickHappened) 
    { return >round widget<} else {return >longWidget<}
        }
    

    You can put this function directly in build as it returns widget either way so UI will build correctly.

    clickHappened being some global bool in the screen widget.

    Login or Signup to reply.
  2. I’m Try to solve your problem

    Here is Code example:

     bool isContainer=true;
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.white,
         body: Center(
           child: InkWell(
             onTap: (){
               setState(() {
                 isContainer=false;
               });
               print("hello tapped");
             },
             child: Container(
    
               height: 40,
               width: 70,
              decoration: BoxDecoration(
                color: Colors.purple,
               borderRadius: BorderRadius.all(Radius.circular(20)),
             ),
    
               child: isContainer?Row(
                 mainAxisAlignment: MainAxisAlignment.center,
                 children: [
    
                   Icon(Icons.contact_mail_outlined),
                   SizedBox(
                     width: 10,
                   ),
                   Text("Add")
                 ],
               ):Container(
                 color: Colors.purple,
                 child:Icon(Icons.contact_page_outlined),
               ),
             ),
           ),
         ),
        );
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search