android - 在 flutter 应用程序中添加时间选择器的正确方法是什么?

标签 android ios flutter dart flutter-layout

在我的应用程序中,用户需要为任务手动选择时间,但我不知道在 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/

相关文章:

android - JSON 解析为具有多个对象 Android 的 ListView

iphone - 如何在 iPhone 上使用 xmlparsing 解析 XML 文件?

ios - "strong"之前的预期属性

Flutter 嵌套的 GestureDetector 不起作用

android - 用户向上滚动时无法单击 SliverPersistentHeader 上的操作按钮

Android:如何根据屏幕设置标题的高度或宽度

android - 将 cookie 传递给 Android WebView

java - BaseDaoImpl 有一个不可见的方法

ios - 核心数据栈结构

flutter - bloc_test : Bad state: Cannot emit new states after calling close