Question Detail

Flutter Switch widget does not working fine

4 years ago Views 3023 Visit Post Reply

Flutter Switch widget does not working fine, i am using switch widget for yes and no options but in flutter i am not able to change swtich button state. when i drag dot left to right only then it is changeing but i want to switch on click event. 

Switch(
          value: false,
          onChanged: (bool val) {},
        ),

also switch doesnt have anything to show my Text.

whats wrong i am doing here?


Thread Reply

Anonymous

- 4 years ago

You have to use setState(){} 

 

bool _acceptTrm=false;

...

  SwitchListTile(
    value: _acceptTrm,
    title: Text('Accept Terms'),
    onChanged: (bool value) {
    setState(() {
     _acceptTrm = value;
   });
 },
),

you have to use SwitchListTile for Text with Switch Widget.