【问题标题】:IOS Date picker in FlutterFlutter 中的 IOS 日期选择器
【发布时间】:2021-03-19 17:55:23
【问题描述】:

我只想使用 Cupertino 制作日期选择器。像下面的东西

但我能做的就是这个......有人可以帮忙吗?

Container(
            height: MediaQuery.of(context).copyWith().size.height / 3,
            child: CupertinoDatePicker(
              initialDateTime: DateTime.now(),
              onDateTimeChanged: (DateTime newdate) {
                print(newdate);
                setState(() {
                  _currentdate = newdate;
                });
              },
              use24hFormat: true,
              maximumDate: new DateTime(2050, 12, 30),
              minimumYear: 2010,
              maximumYear: 2018,
              minuteInterval: 1,
              mode: CupertinoDatePickerMode.dateAndTime,
            ),
          ),

【问题讨论】:

  • This article by the Flutter Agency 应该提供您正在寻找的内容。这不是我的代码,所以我不会回答它,但它帮助我制作了一个不错的 Cupertino 选择器,就像你问的那样。我什至添加了一个中心按钮来“重置”日期。而不是一个“保存”按钮,你可以换成你的“截止日期”。

标签: flutter datepicker flutter-cupertino cupertinopicker


【解决方案1】:
  1. 在 Cupertino 日期选择器顶部添加一行。
  2. 使用 intl 包格式化所选日期。
           Column(
             children: [
                Container(
                  decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(color: Colors.grey, width: 0.5))),
                  padding: EdgeInsets.symmetric(
                    horizontal: 20,
                    vertical: 10,
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        'Due date',
                        style: TextStyle(
                            color: Colors.grey,
                            fontSize: 17),
                      ),
                      Text(
                        DateFormat('MMM, dd yyyy').format(_currentdate??DateTime.now(),
                        style: TextStyle(
                            color: Colors.blue,
                            fontSize: 17),
                      ),
                    ],
                  ),
                ),
                Container(
                  height: MediaQuery.of(context).copyWith().size.height / 3,
                  child: CupertinoDatePicker(
                    initialDateTime: DateTime.now(),
                    onDateTimeChanged: (DateTime newdate) {
                      print(newdate);
                      setState(() {
                        _currentdate = newdate;
                      });
                    },
                    use24hFormat: true,
                    maximumDate: new DateTime(2050, 12, 30),
                    minimumYear: 2010,
                    maximumYear: 2018,
                    minuteInterval: 1,
                    mode: CupertinoDatePickerMode.dateAndTime,
                  ),
                ),
              ]),

【讨论】:

    猜你喜欢
    • 2020-02-05
    • 2023-03-07
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 2018-02-22
    • 2021-07-17
    • 1970-01-01
    • 2021-07-28
    相关资源
    最近更新 更多