How to implement CheckBox in Flutter?

Dharam Dutt Mishra picture Dharam Dutt Mishra · Oct 15, 2018 · Viewed 48.8k times · Source

Here I have mentioned my code of checkbox. I am new to flutter, So I have to implement it for Remember me functionality.

Code:

 Container(
 padding: EdgeInsets.all(10.0),
  child: Column(
    children: <Widget>[
     new Checkbox(value: checkBoxValue,
          activeColor: Colors.green,
          onChanged:(bool newValue){
        setState(() {
          checkBoxValue = newValue;
        });
       Text('Remember me');
          }),
    ],
  ),
);

Answer

Nikhat Shaikh picture Nikhat Shaikh · May 3, 2019

If you need a Checkbox with a label then you can use a CheckboxListTile

CheckboxListTile(
    title: Text("title text"),
    value: checkedValue,
    onChanged: (newValue) { 
                 setState(() {
                   checkedValue = newValue; 
                 }); 
               },
    controlAffinity: ListTileControlAffinity.leading,  //  <-- leading Checkbox
  )