我怎样才能禁用颤动开关
How can I disabled flutter switch
在我的帮助屏幕中,我有这个开关,其目的是什么也不做,只是按原样显示。
但是我现在遇到的问题是,即使它什么都不做,用户也可以拖动开关,所以我想弄清楚如何禁用它,这样就没有人可以拖动切换按钮。
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())
],
),
),
),
);
}
要禁用您的 Switch
,请像这样将其 onChanged
方法编辑为 null
Switch(
onChanged: null,
value: true,
inactiveThumbColor: Colors.tealAccent,
inactiveTrackColor: Colors.tealAccent.withOpacity(0.5),
// ...
),
如果你想要手动设置值的静态开关,请考虑使用 AbsorbPointer。它不会改变您的开关外观,也不会禁用它。
AbsorbPointer 只是阻止用户与元素交互
在我的帮助屏幕中,我有这个开关,其目的是什么也不做,只是按原样显示。
但是我现在遇到的问题是,即使它什么都不做,用户也可以拖动开关,所以我想弄清楚如何禁用它,这样就没有人可以拖动切换按钮。
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())
],
),
),
),
);
}
要禁用您的 Switch
,请像这样将其 onChanged
方法编辑为 null
Switch(
onChanged: null,
value: true,
inactiveThumbColor: Colors.tealAccent,
inactiveTrackColor: Colors.tealAccent.withOpacity(0.5),
// ...
),
如果你想要手动设置值的静态开关,请考虑使用 AbsorbPointer。它不会改变您的开关外观,也不会禁用它。 AbsorbPointer 只是阻止用户与元素交互