在我的应用程序中,用户需要为任务手动选择时间,但我不知道在 Flutter 应用程序中使用时间选择器并由用户手动选择时间(一天)的正确方法是什么。
最佳答案
首先在类级别声明这个变量,
TimeOfDay selectedTime = TimeOfDay.now();
然后调用这个方法 -Future<void> _selectTime(BuildContext context) async {
final TimeOfDay picked_s = await showTimePicker(
context: context,
initialTime: selectedTime, builder: (BuildContext context, Widget child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false),
child: child,
);});
if (picked_s != null && picked_s != selectedTime )
setState(() {
selectedTime = picked_s;
});
}
关于android - 在 flutter 应用程序中添加时间选择器的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63223855/