3

我只想使用 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,
            ),
          ),

4

1 回答 1

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,
                  ),
                ),
              ]),

于 2021-06-23T09:48:22.033 回答