在我的帮助屏幕中,我有此开关,其目的是不做任何事情,而只是按原样显示。
但是我现在遇到的问题是,即使它什么也没做,用户仍然可以拖动开关,因此我试图弄清楚如何禁用它,从而没人可以拖动开关按钮。
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())
],
),
),
),
);
}
要禁用swith编辑,它的onChanged
方法为null,像这样
Switch(
onChanged: null,
value: true,
inactiveThumbColor: Colors.tealAccent,
inactiveTrackColor: Colors.tealAccent.withOpacity(0.5),
// ...
),
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句