switchItem static method
Widget
switchItem({
- Icon? icon,
- required String title,
- bool value = false,
- ValueChanged<
bool> ? onChanged,
switch定义, onChanged
icon
左侧图标,可不定义
title
标题文本
value
选择状态
onChanged
点击事件
Implementation
static Widget switchItem({
Icon? icon,
required String title,
bool value = false,
final ValueChanged<bool>? onChanged,
}) {
Widget switchWidget;
if (Platform.isAndroid) {
switchWidget = Switch(
value: value,
onChanged: onChanged,
);
} else {
switchWidget = CupertinoSwitch(
value: value,
onChanged: onChanged,
);
}
return ItemNormalWidget(
leading: icon,
title: Text(title),
trailing: switchWidget,
onTap: () {
if (onChanged != null) {
onChanged(value);
}
},
);
}