【问题标题】:Cannot show date picker over bottom sheet无法在底部工作表上显示日期选择器
【发布时间】:2019-07-27 17:55:34
【问题描述】:

我试图在BottomSheet 上显示DatePicker,但出现以下错误:

Unhandled Exception: 'package:flutter/src/widgets/routes.dart':
Failed assertion:
line 1557 pos 10: '!barrierDismissible || barrierLabel != null': is not true.

这是我的代码:

  Future<DateTime> _selectDate(context) async {
    return await showDatePicker(
      context: context,
      firstDate: DateTime(2018),
      initialDate: DateTime.now(),
      lastDate: DateTime(2025),
    );
  }

【问题讨论】:

  • 你能分享你用来显示选择器的代码吗?
  • 确定,已更新

标签: android ios flutter flutter-layout


【解决方案1】:

BottomSheet 类需要一个 WidgetBuilder(意味着您需要一个小部件) 但 showDatePicker() 不提供任何 Widget。

如果您需要 BottomSheet 上的日期选择器。我更喜欢使用 Cupertino DatePicker。

此处示例:https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/cupertino/cupertino_picker_demo.dart

【讨论】:

  • 如果需要 Material 风格,解决方案是什么?
  • 不应该将日期选择器包装在 Material 小部件(例如 Card)中吗?
  • 我认为自定义小部件是唯一的解决方案。
  • 是否有任何解决方案在底页上带有材质样式的日历?
猜你喜欢
  • 2018-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-14
  • 2020-12-11
  • 1970-01-01
相关资源
最近更新 更多