flutter - 如何使颤动中的切换按钮弹出日历和时间
问题描述
我想创建两个切换按钮,它们将显示从日历中选择日期和时间的选项,但日历不会弹出。我试图寻找一些答案,但找不到任何东西。
代码:
Padding(
padding: const EdgeInsets.fromLTRB(0, 400, 256, 0),
child: ToggleButtons(
children: <Widget>[
Icon(Icons.bluetooth),
Icon(Icons.wifi),
Icon(Icons.flash_on),
],
isSelected: _isSelected,
),
),
列表
List<bool> _isSelected = [false, true, false];
解决方案
将您的CupertinoSwitch
内部包裹起来ListTile
。然后onTap
打开一个CupertinoDatePicker
或任何您选择的日历选择器。例如:
ListTile(
title: Text(
'Time',
style: TextStyle(color: Colors.white),
),
trailing: CupertinoSwitch(
activeColor: Color(0xff59a3fd),
value: globals.isEnable //your switch value here
onChanged: (bool value) {
setState(() {
globals.isEnable = value;
});
},
),
onTap: () {
//Open your calender here
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return _buildBottomPicker(
CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
initialDateTime: date,
onDateTimeChanged: (DateTimeaddSelectedDate){
setState(() {
this.newDateTime = addSelectedDate;
date = newDateTime;
});
},
),
);
},
);
},
)
推荐阅读
- python - 无法从 Dockerfile 为烧瓶 python 应用程序构建?
- java - 在 JUnit 5 中将测试摘要打印到控制台
- parallel-processing - 如何在与 GNU-parallel 并行的循环中并行化 csh
- python - 是否有任何工具或算法可以将 3D 点云转换为 2.5D 图像?
- reactjs - 在 React.js 中使用分页进行实时搜索
- javascript - 使用 Tagsinput Bootstrap 在 console.log 上重复值
- node.js - Summernote 不能在 laravel 中使用 npm
- flutter - Flutter,如何更改列表视图项的大小?
- python - “ AttributeError:‘用户’对象没有属性‘编辑’” discord.py 错误
- linux - 在 Heroku 上达到的文件观察者数量的系统限制