调用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. win7下redis开机自启动设置

    win7下安装完redis之后,每次开机都得用cmd命令行启动redis,所以就想办法实现开机自启动redis. 一.把启动命令写入bat: E:\redis\redis-server.exe E:\ ...

  2. GIS矢量大数据采集

    1.使用什么工具采集 2.在哪个网站采集 3.采集哪一种数据 >>地理大数据公众号 >>大数据公众号 >>智能数据湖公众号 点.线.面.体 可视化 >> ...

  3. html、css、js分工,内核,html头,html表单

    html:内容css:样式js:交互 内核 浏览器控制台输入navigator.userAgent,回车显示出内核"Mozilla/5.0 (Windows NT 6.1; WOW64) A ...

  4. app中使用

    KeepLive.startWork(this, KeepLive.RunMode.ROGUE, ForegroundNotification("Title", "mes ...

  5. Linux shell 归纳之 cp

    1. 复制文件夹folder1(包括所有子文件夹和文件), 并命名为folder2 # cp -r /usr/folder1 folder2 2. 复制文件file1 到它的上一级的目录的abc文件夹 ...

  6. 2019牛客暑期多校训练营(第六场)C - Palindrome Mouse (回文自动机)

    https://ac.nowcoder.com/acm/contest/886/C 题意: 给出一个串A , 集合S里面为A串的回文字串 , 现在在集合S里面找出多少对(a,b),b为a的字串 分析: ...

  7. Jira中的Tempo查看component以及issue的工作量汇总

    在右侧group by的地方,同时选中component和issue

  8. webService接口的py文件打包成exe

    (一)webService接口的py文件打包成exe,在python3.5版本.pyInstaller3.2版本.pywin32-219.win-amd64-py3.5版本打包时报错,原因可能是pyi ...

  9. java数组,遍历数组

    数组:一组具有相同数据类型的集合(容器) 1.数组声明格式: 数据类型 [] 数组名 = new 数据类型[长度]: 数组长度一旦确定无法更改. 数组里的数据必须是相同类型或自动向上转型后兼容的类型 ...

  10. springboot jpa 级联操作及测试问题 (@Transactional与@Test)

    前言:测试springboot版本     :springBootVersion = '2.0.5.RELEASE' 一 :搬运@Transactional B. 如果加了事务,必须做好开发环境测试( ...