flutter - 在 Flutter 中从 timePicker 选择时间后如何删除 TimeOfDay 文本

标签 flutter

我在 Flutter 中使用 timePicker。

一旦我从弹出对话框中选择了时间,它就会显示选择的时间,但它不仅会显示时间,例如:12:45,还会显示 TimeOfDay,例如:TimeOfDay (12:45)

如何去掉 TimeOfDay 文本?

//Declaration example
TimeOfDay _time = new TimeOfDay.now();
//Time picker example code
Future<Null> _selectTime(BuildContext context) async {
    final TimeOfDay picked = await showTimePicker(context: context, initialTime: _time);`

    if (picked != null && picked != _time) {
      print('${_time.toString()}');
      setState(() {
        _time = picked;
      });
    }
  }
//Display example
Text(
   '${_time.toString()}',
),

我希望时间看起来像:12:45 而不是:TimeOfDay(12:45)

最佳答案

这将以所需格式打印。

Text(
   _time.format(context),
),

关于flutter - 在 Flutter 中从 timePicker 选择时间后如何删除 TimeOfDay 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56682711/

相关文章:

flutter - 在 flutter 中为 slider 使用离线图像

flutter : This expression has a type of 'void' so its value can't be used

flutter - 如何在flutter中检测iOS或Android设备底部是否有HomeBar

flutter - 将动画从屏幕右侧翻译到外部

flutter - 如何实现依赖于另一个提供程序的提供程序?

flutter - 如何在 Flutter 中更新现有文件(Path_Provider)

java - Flutter 应用程序体积太大

dart - 在 Dart 中将字符串转换为 map

function - 动态调用功能

flutter - 为同一情况切换具有多个值的情况