zoukankan      html  css  js  c++  java
  • 27flutter日期 时间组件flutter_cupertino_date_picker的使用

    pubspec.yaml

    flutter_cupertino_date_picker: ^1.0.12

    DatePicker.dart

    import 'package:date_format/date_format.dart';
    import 'package:flutter/material.dart';
    import 'package:flutter_cupertino_date_picker/flutter_cupertino_date_picker.dart';
    class DatePickerPubDemo extends StatefulWidget {
      DatePickerPubDemo({Key key}) : super(key: key);
      _DatePickerPubDemoState createState() => _DatePickerPubDemoState();
    }
    
    class _DatePickerPubDemoState extends State<DatePickerPubDemo> {
      DateTime _dateTime=DateTime.now();
      _showDatePicker(){
        DatePicker.showDatePicker(
          context,
          pickerTheme: DateTimePickerTheme(
            showTitle: true,
            confirm: Text('确定',style:TextStyle(color:Colors.red)),
            cancel: Text('取消',style: TextStyle(color: Colors.cyan)),
          ),
          minDateTime: DateTime.parse("1980-05-21"),
          maxDateTime: DateTime.parse("2019-05-21"),
          initialDateTime: _dateTime,
          // dateFormat: "yyyy-MMMM-dd", //只包含年、月、日
          dateFormat: 'yyyy年M月d日  EEE,H时:m分',
          pickerMode: DateTimePickerMode.datetime,
          locale: DateTimePickerLocale.zh_cn,
          onCancel: (){
            debugPrint("onCancel");
          },
          onConfirm: (dateTime,List<int> index){
            setState(() {
              _dateTime=dateTime;
            });
          }
        );
      }
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('日期选中'),
          ),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  InkWell(
                    child: Row(
                      children: <Widget>[
                        // Text("${formatDate(_dateTime,[yyyy,'年',mm,'月',dd])}"), //只获取年月日
                        Text("${formatDate(_dateTime,[yyyy,'年',mm,'月',dd,' ',HH,':',nn])}"),
                        Icon(Icons.arrow_drop_down)
                      ],
                    ),
                    onTap:_showDatePicker,
                  )
                ],
              )
            ],
          ),
        );
      }
    }
  • 相关阅读:
    STM32——项目需求之低功耗的停机模式
    sscanf函数——强大的C语言库函数
    二级指针偏移
    RTX基础教程目录
    #pragma pack(push) 和#pragma pack(pop) 以及#pragma pack()
    Write thread-safe servlets [reproduced]
    C++程序员如何转Java
    How to implement equals() and hashCode() methods in Java[reproduced]
    The Java Enum: A Singleton Pattern [reproduced]
    VS Code
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/11549204.html
Copyright © 2011-2022 走看看