How to apply checkbox in flutter

Posted by

step 1

set variable in class


String myflight;

bool Flight = false;

Implement in Route in onpress()

                                    onPressed: () {
                                      setState(() async {
                                        _controllerCategory.text =
                                            widget.Category;
                                            String myflights= 
                                             myflight.toString(); 
                                            ;
                                            widget._isLoading = true;
            
                                            _isallLoading == true
                                                ? _storemytrip(
                                                    myflights,
                                                  );
                                          });
                                        }
                                      });
                                    }

Implement cheakbox

  Widget _buildCheckboxFlight() => ListTile(
        title: Text(
          'Flight',
          style: TextStyle(
            color: Colors.black54,
            fontSize: 16,
          ),
        ),
        trailing: Checkbox(
          value: Flight,
          onChanged: (bool? value) {
            setState(() {
              this.Flight = value!;
              if(Flight==true){
              myflight=1.toString();
              print("myflight");
              print(myflight);
              }
                else{
              myflight=0.toString();
              print(" else myflight");
              print(myflight);
              }
              print(Flight);
              print(this.Flight);
            });
          },
        ),
      );

Output

And if want to know to ternary operator in flutter.If you want more clarity output please click here.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x