颤振 - 如何将"Switch"转换为"raised button"(推送通知)?



我想转换一个"开关";到"凸起按钮"或类似,并得到相应的函数…

**Switch(
onChanged: (bool enabled) {
setState(() {
_notificationsEnabled = enabled;
_updateNotifications(enabled);
});
},
value: _notificationsEnabled,
),**

摘自总代码:

Container(
margin: EdgeInsets.only(top: 5.0, bottom: 5.0, right: 5.0, left: 5.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.black.withOpacity(0.13)
)
)
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('PUSH-BENACHRICHTIGUNGEN AKTIVIEREN', style: TextStyle(color: isDark ? Colors.cyanAccent : Color(0xFF000000), fontFamily: "Storopia", fontSize: 13.0)),
**Switch(
onChanged: (bool enabled) {
setState(() {
_notificationsEnabled = enabled;
_updateNotifications(enabled);
});
},
value: _notificationsEnabled,
),**
],
),
),

图示目标是创建一个"凸起按钮"。当推送通知被激活时,它会亮绿色,当它们被关闭时,它会亮红色,而不是开关。我不确定是否有一个简单的解决方案,但我希望有人有一个简单的解决方案,因为我是一个新手。我以前在这里得到过帮助,而且非常容易和快速,我完全惊讶,觉得这里有这样一个活跃的社区真是太棒了

**Switch(
onChanged: (bool enabled) {
setState(() {
_notificationsEnabled = enabled;
_updateNotifications(enabled);
});
},
value: _notificationsEnabled,
),**

可以使用三元类型:

// Below your stateful widget class
bool _enabled = false;
// [...]
RaisedButton(
color: _enabled ? Colors.green : Colors.red,
onPressed: () {
setState(() {
_enabled = !_enabled;
_updateNotifications(_enabled);
});
},
child: Text(_enabled? "On" : "Off")),

最新更新