调用Flutter的第三方时间选择器组件

上面我介绍了系统给我们提供的日期时间选择器,但是有时候系统提供的选择器并不符合我们的要求,这时我们就可以到pub.dev上去寻找符合我们要求的日期选择器。

这里我们介绍一款Cupertino风格(即iOS风格)的日期选择器——flutter_cupertino_date_picker。

使用代码如下:

import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cupertino_date_picker/flutter_cupertino_date_picker.dart'; class TimePickerPage extends StatefulWidget {
TimePickerPage({Key key}) : super(key: key); _TimePickerPageState createState() => _TimePickerPageState();
} class _TimePickerPageState extends State<TimePickerPage> {
DateTime _selectedDateTime = DateTime.now(); @override
Widget build(BuildContext context) {
void _showDatePicker() {
DatePicker.showDatePicker(
context,
pickerTheme: DateTimePickerTheme(
showTitle: true,
confirm: Text('custom Done', style: TextStyle(color: Colors.red)),
cancel: Text('custom cancel', style: TextStyle(color: Colors.cyan)),
),
minDateTime: DateTime.parse("2010-05-12"), //选择器上可选择的最早时间
maxDateTime: DateTime.parse("2021-11-25"), //选择器上可选择的最晚时间
initialDateTime: _selectedDateTime, //选择器的当前选中时间
dateFormat: "yyyy-MMMM-dd", //时间格式
locale: DateTimePickerLocale.zh_cn, //国际化配置
onClose: () => print("----- onClose -----"),
onCancel: () => print('onCancel'),
onChange: (dateTime, List<int> index) {
setState(() {
_selectedDateTime = dateTime;
});
},
onConfirm: (dateTime, List<int> index) {
setState(() {
_selectedDateTime = dateTime;
});
},
);
} /// Display time picker.
void _showDateTimePicker() {
DatePicker.showDatePicker(
context,
minDateTime: DateTime.parse("2019-05-15 09:23:10"),
maxDateTime: DateTime.parse("2020-06-03 21:11:00"),
initialDateTime: DateTime.parse(formatDate(_selectedDateTime, [yyyy, "-", mm, "-", "dd", " ", HH, ":", nn, ":", ss])),
dateFormat: "yy年M月d日 EEE,H时:m分",
locale: DateTimePickerLocale.zh_cn,
pickerTheme: DateTimePickerTheme(
showTitle: true,
),
pickerMode: DateTimePickerMode.datetime, // show TimePicker
onCancel: () {
debugPrint('onCancel');
},
onChange: (dateTime, List<int> index) {
setState(() {
_selectedDateTime = dateTime;
});
},
onConfirm: (dateTime, List<int> index) {
setState(() {
_selectedDateTime = dateTime;
});
},
);
} return Scaffold(
appBar: AppBar(title: Text("时间选择器演示页面")),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () {
_showDatePicker();
},
child: Row(
children: <Widget>[
Text(formatDate(
_selectedDateTime, [yyyy, "-", mm, "-", dd])),
Icon(Icons.arrow_drop_down)
],
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () {
_showDateTimePicker();
},
child: Row(
children: <Widget>[
Text(formatDate(_selectedDateTime,
[yyyy, "-", mm, "-", dd, " ", HH, ":", nn])),
Icon(Icons.arrow_drop_down)
],
),
)
],
)
],
),
);
}
}

Flutter第三方選擇器組件的更多相关文章

  1. jquery 選擇器

    jquery 選擇器有: 元素選擇器: $("p")選擇所有<p> $("p.intro")選擇所有class=“intro”的<p> ...

  2. ColorPic 一套簡單好用的顏色選擇器!

    做美工的時候,常常會有配色.抓取顏色及獲取顏色代碼的困擾,專業人士可能有很好的工具來協助,但對於偶爾需要或非經常接觸美工的人來說,即便是有很好的工具,也還要花很多時間進行學習,常常就是看到一個漂亮的顏 ...

  3. [T-SQL] NCL INDEX 欄位選擇效能影響-解析

    因為這篇文章寫的比較長一些,我就將總結先列出來 總結 1. 除了WHERE條件外,JOINColumn除了記得建立索引,也要注意到選擇性的高低,如果真的找不到可用的Column,可以考慮在兩邊關聯的表 ...

  4. Qt上FFTW組件的编译与安裝

    Qt上FFTW組件的編譯安裝 FFTW是一個做頻譜非常實用的組件,本文講述在Windows和Linux兩個平臺使用FFTW組件.Windows下的的FFTW組件已經編譯好成爲dll文件,按照開發應用的 ...

  5. 用Razor語法寫範本-RazorEngine組件介紹【转——非常好,可以用它来代替NVelocity】

    RazorEngine 官網網址:http://razorengine.codeplex.com 在找到RazorEngine之前曾經想過其他的方案,如T4與V8 Engine載jquery.temp ...

  6. DC DC電路電感的選擇

    注:只有充分理解電感在DC/DC電路中發揮的作用,才能更優的設計DC/DC電路.本文還包括對同步DC/DC及異步DC/DC概念的解釋.   DCDC電路電感的選擇 簡介 在開關電源的設計中電感的設計為 ...

  7. 用Razor語法寫範本-RazorEngine組件介紹

    最近剛好有要寫寄Email的程式,在代碼中寫HTML覺得很呆,抽出代碼外寫到txt或html檔當範本,由程式執行時在載入檔案時用Regex換關鍵字又覺得不夠好用,而且因為有時會有要判斷一些條件,就會寫 ...

  8. 何解決 LinqToExcel 發生「無法載入檔案或組件」問題何解決 LinqToExcel 發生「無法載入檔案或組件」問題

    在自己的主機上透過 Visual Studio 2013 與 IISExpress 開發與測試都還正常,但只要部署到測試機或正式機,就是沒辦法順利執行,卡關許久之後找我協助.我發現錯誤訊息確實很「一般 ...

  9. C# 選擇本機檔案並上傳

    參考自:http://www.dotblogs.com.tw/puma/archive/2008/11/07/5910.aspxhttp://www.codeproject.com/Articles/ ...

随机推荐

  1. Java 设计模式之 Command 设计模式

    首先我们先来看 UML 图: 参考资料: java设计模式-Command(命令)模式 - - ITeye技术网站http://men4661273.iteye.com/blog/1633775 JA ...

  2. curry柯里化

    Function.prototype.method = function(name,func){ if(!this.prototype[name]){ this.prototype[name] = f ...

  3. ANTLR4将BF翻译成CPP

    实验环境: 操作系统:windows 10 JAVA:JDK 1.8 antlr:antlr-4.7.1-complete.jar IDE:IntelliJ IDEA 2017.2.7 实验目的: 实 ...

  4. 使用 GitLab 的 OAuth2 认证服务

    原文地址 本文档讲述如何使用 GitLab 作为 OAuth 认证服务提供商,以通过 GitLab 的 OAuth 认证登录其他服务(例如持续集成工具 Drone). 如果想使用其他 OAuth 身份 ...

  5. Optimal Value Functions and Optimal Policy

    Optimal Value Function is how much reward the best policy can get from a state s, which is the best ...

  6. linux下的sleep()和usleep()的使用和区别

    函数名: sleep头文件: #include<windows.h> // 在VC中使用带上头文件              #include<unistd.h>    // ...

  7. SQL查询返回去除重复数据的结果集

    方法一: select * from  tablename  where  id   in   (select  id  from  tablename   group  by  id   havin ...

  8. jmeter 非GUI执行测试,没有响应数据保存到jtl文件办法

    估计是jmeter为了减轻客户机负担,就没又默认把这些信息保存,如果想要保存,也可以,需要做出如下配置: 修改bin目录下的user.properties文件,追加配置: jmeter.save.sa ...

  9. Netty之Page级别的内存分配

    Page 级别的内存分配: 之前我们介绍过, netty 内存分配的单位是chunk, 一个chunk 的大小是16MB, 实际上每个chunk, 都以双向链表的形式保存在一个chunkList 中, ...

  10. Oracle-随笔笔记

    1.重命名数据库表.重命名字段 alter table tablename1 rename to tablename2; alter table tablename1 rename column co ...