0
votes

I am trying to Show the showModelBottomSheet() and It's perfectly working ,There is a Button in bottomSheet ,,So Whenever I pressed this Button it Show/ return a new Container(container different Widgets).Upon this onTap() ,I have set bool variable to be true or false... but Doesn't work.Does setState(()); Method Doesn't work in ModelBottomSheet ? and Similar Case with showGeneralDialog()... How Can I fix both .

bool p=true;
showModalBottomSheet(
  backgroundColor: Colors.transparent,
    enableDrag: true,
    isScrollControlled: true,
    context: context, builder: (BuildContext context){

  return p==true?Container(
    width: MediaQuery.of(context).size.width,
    height: MediaQuery.of(context).size.height/2,
    padding: EdgeInsets.all(5.0),
    decoration: BoxDecoration(
      color: Theme.of(context).primaryColor,
      borderRadius: BorderRadius.only(topLeft: Radius.circular(20.0),topRight: Radius.circular(20.0)),
    ),
    child: Column(
      children: <Widget>[
        Container(
          alignment: Alignment.topLeft,
          width: MediaQuery.of(context).size.width,
          height: 30.0,
          child: IconButton(icon: Icon(Icons.arrow_downward,color: Colors.white,size: 32.0,), onPressed: (){
            Navigator.pop(context);
          }),
        ),

        Text(widget.model.cName,style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 25.0,fontFamily: 'Rajdhani'),),

        SizedBox(height: 10.0,),
        Text('AMOUNT',style: TextStyle(color: Colors.white60,fontWeight: FontWeight.w100,fontSize: 12.0),),

        SizedBox(height: 20.0,),
        Text(widget.model.b,style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 32.0,fontFamily: 'Rajdhani'),),

        SizedBox(height: 10.0,),
        Text('REPEAT',style: TextStyle(color: Colors.white60,fontWeight: FontWeight.bold,fontSize: 12.0,fontFamily: 'Rajdhani'),),
        SizedBox(height: 15.0,),
        Text('EVERY MONTH AT   '+widget.model.date,style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 20.0,fontFamily: 'Rajdhani'),),


        SizedBox(height: 20.0,),
        GestureDetector(
          onTap: (){
            pay=false;
            print('ayeeee $p');
          },
          child: Container(
            alignment: Alignment.bottomCenter,
            width: MediaQuery.of(context).size.width*0.8,
            height: 40.0,
            decoration: BoxDecoration(color: Colors.white,
              borderRadius: BorderRadius.circular(10.0),
            ),
            child: Center(
              child: Text('P ',style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold,fontSize: 18.0,fontFamily: 'Rajdhani')),
            ),
          ),
        ),




      ],
    ),
  ):Container(
    width: MediaQuery.of(context).size.width,
    height: MediaQuery.of(context).size.height/2,
    padding: EdgeInsets.all(5.0),
    decoration: BoxDecoration(
      color: Theme.of(context).primaryColor,
      borderRadius: BorderRadius.only(topLeft: Radius.circular(20.0),topRight: Radius.circular(20.0)),
    ),
    child: Column(
      children: <Widget>[
        Container(
          alignment: Alignment.topLeft,
          width: MediaQuery.of(context).size.width,
          height: 30.0,
          child: IconButton(icon: Icon(Icons.arrow_downward,color: Colors.white,size: 32.0,), onPressed: (){
            Navigator.pop(context);
          }),
        ),

        Text('AMOUNT',style: TextStyle(color: Colors.white60,fontWeight: FontWeight.w100,fontSize: 12.0),),

        SizedBox(height: 20.0,),
        Text(widget.model.b,style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 32.0,fontFamily: 'Rajdhani'),),

        SizedBox(height: 10.0,),
        Text('SOURCE',style: TextStyle(color: Colors.white60,fontWeight: FontWeight.bold,fontSize: 12.0,fontFamily: 'Rajdhani'),),
        SizedBox(height: 15.0,),
        Text('EVERY MONTH AT   '+widget.model.date,style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600,fontSize: 20.0,fontFamily: 'Rajdhani'),),


        SizedBox(height: 20.0,),
        Container(
          alignment: Alignment.bottomCenter,
          width: MediaQuery.of(context).size.width*0.8,
          height: 40.0,
          decoration: BoxDecoration(color: Colors.white,
            borderRadius: BorderRadius.circular(10.0),
          ),
          child: Center(
            child: Text('PA ',style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold,fontSize: 18.0,fontFamily: 'Rajdhani')),
          ),
        ),




      ],
    ),
  );
1

1 Answers

1
votes

To update the state of a bottom sheet, you need to wrap your widget with a StatefulBuilder and use the StateSetter provided to set the state:

I added an example below:

showModalBottomSheet(
        context: context,
        builder: (context) {
          return StatefulBuilder(
              builder: (BuildContext context, StateSetter setModalState) {
            return  // ** YOUR WIDGETS ** 
          });
    });