【发布时间】:2022-07-20 17:48:20
【问题描述】:
我的应用中有一个抽屉,我想在其中保持拨动开关的状态。 我怎样才能做到这一点 ? 这是代码
SizedBox(
height: 40,
child: ListTile(
leading: SizedBox(
height: 25,
width: 25,
child: Image.asset(
'assets/sideMenu/Bell.png',
),
),
title: Transform.translate(
offset: const Offset(-14, 0),
child: const Text('Notifications',
style: TextStyle(
fontSize: 12, color: Colors.white))),
trailing: SizedBox(
height: 20,
width: 40,
child: Transform.scale(
scale: 1.3,
child: Switch.adaptive(
value: value,
activeColor: Colors.white,
activeTrackColor: const Color.fromARGB(
255, 35, 187, 40),
onChanged: (value) =>
setState(() => this.value = value)),
)),
),
),
我能做些什么来让它保持它的状态?
这就是它现在的工作方式:
【问题讨论】:
-
你能包含你的构建方法吗?
-
使用值通知器来维护状态和值通知器构建器在没有任何状态管理解决方案的情况下监听更改
标签: flutter dart flutter-layout