Umer
Umer

Reputation: 203

horizontally align check box and text in center in flutter

I am trying to align the text and the check box in center , but its not working , is this the wrong implementation :

      Column(
            children: <Widget>[
              Align(
                alignment: Alignment.center ,
                child:ListTile(
                  leading: Checkbox(
                    activeColor: pColor,
                    value: select,
                    onChanged: (bool nValue) {
                      setState(() {
                        select = nValue;
                      });
                    },
                  ),
                  title: Text("Show me"),
              ),

              ),

this is how it looks :

enter image description here

I am trying to align the text and the check box right above the text "continue" in the center

Upvotes: 1

Views: 2593

Answers (2)

rph
rph

Reputation: 116

This works for me quite well using CheckboxListTile:

 Align(
      alignment: Alignment.center, // change this for right/left alignment
      child: Container(
        width: 300,// Adjust this dependent on Text size
        child: CheckboxListTile(
          title: Text('Show me'),
          value: true,
          onChanged: (bool? value) {},
          controlAffinity: ListTileControlAffinity.leading, // checkbox position left
        ),
      ),
    ),

Upvotes: 0

Nilesh Senta
Nilesh Senta

Reputation: 5470

You should wrap ListTile with Container and give width to Container.

Column(children: <Widget>[
      Align(
      alignment: Alignment.center,
        child: Container(width: 200,
          child: ListTile(
            leading: Checkbox(
              activeColor: pColor,
              value: select,
              onChanged: (bool nValue) {
                setState(() {
                  select = nValue;
                });
              },
            ),
            title: Text("Show me"),
          ),
        ),
      ),
    );

This works for me

Upvotes: 1

Related Questions