颤振:颤振中的iOS样式日期选择器

时间:2020-06-04 07:16:04

标签: flutter

我如何在flutter中添加iosstyle datepicker并将其设置为文本字段。我尝试了几件事,但是失败了。.获取android风格的datepicker并进行设置有很多解决方案,但是ios风格的datepicker却没有很多解决方案。.谢谢您的帮助

enter image description here

2 个答案:

答案 0 :(得分:1)

flutter_datetime_picker:

导入'package:flutter_datetime_picker / flutter_datetime_picker.dart';

String _date = "Date of Birth";

 Padding(padding: EdgeInsets.symmetric(
                        vertical: 10.0, horizontal: 16.0),
                      child: Column(
                        children: <Widget>[
                          SizedBox(
                            height: 60.0,
                            child: FlatButton(
                              shape: RoundedRectangleBorder(
                                  side: BorderSide(
                                    color: Colors.orangeAccent
                                  ),
                                  borderRadius: BorderRadius.circular(5.0)),
                              onPressed: () {
                                DatePicker.showDatePicker(context,
                                    theme: DatePickerTheme(
                                      containerHeight: 210.0,
                                    ),
                                    showTitleActions: true,
                                    minTime: DateTime(1900, 1, 1),
                                    maxTime: DateTime.now(), onConfirm: (date) {
                                      print('confirm $date');
                                      _date = '${date.day}/${date.month}/${date.year}';
                                      setState(() {});
                                    }, currentTime: DateTime.now(), locale: LocaleType.en);
                              },
                              child: Container(
                                alignment: Alignment.center,
                                height: 50.0,
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: <Widget>[
                                    Row(
                                      children: <Widget>[
                                        Container(

                                          child: Row(
                                            children: <Widget>[
                                              Icon(
                                                Icons.cake,

                                                color: Colors.black54,
                                              ),
                                              Text(
                                                "  $_date",
                                                style: TextStyle(
                                                    color: Colors.black,
                                                    fontSize: 17.0,
                                                fontStyle: FontStyle.normal),
                                              ),
                                            ],
                                          ),
                                        )
                                      ],
                                    ),
                                    Icon(Icons.date_range,color: Colors.black45,)

                                  ],
                                ),
                              ),
                              color: Colors.white,
                            ),
                          ),
                          // datetime()
                        ],
                      ),
                    ),

答案 1 :(得分:0)

使用这个

      void _showIOS_DatePicker(ctx) {
    showCupertinoModalPopup(
        context: ctx,
        builder: (_) => Container(
              height: 190,
              color: Color.fromARGB(255, 255, 255, 255),
              child: Column(
                children: [
                  Container(
                    height: 180,
                    child: CupertinoDatePicker(
                        initialDateTime: DateTime.now(),
                        onDateTimeChanged: (val) {
                          setState(() {
                            dateSelected = val.toString();
                          });
                        }),
                  ),
                ],
              ),
            ));
  }

enter image description here