Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disabled flutter switch

In my help screen, I have this switch and the purpose for that is to do nothing but just display like the way it is.

But the problem I'm having right now, even though it doesn't do anything, the user can drag the switch so I'm trying to figure out how I can disabled it so that no one can drag the switch button.

    return Container(
      child: Card(
        color: Theme.of(context).primaryColor,
        margin: EdgeInsets.only(bottom: 30, top: 10),
        child: ListTile(
          title: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text("Dark Theme",
                  style: TextStyle(color: Theme.of(context).accentColor)),
              Switch(
                  value: true,
                  onChanged: (value) {},
                  activeColor: Theme.of(context).accentColor),
              Text("Light Theme", style: TextStyle())
            ],
          ),
        ),
      ),
    );
  }

enter image description here

enter image description here


1 Answers

To disable your Switch, edit its onChanged method to null like this

Switch(
  onChanged: null,
  value: true,
  inactiveThumbColor: Colors.tealAccent,
  inactiveTrackColor: Colors.tealAccent.withOpacity(0.5),
  // ...
),
like image 145
dm_tr Avatar answered Jan 24 '26 16:01

dm_tr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!