Flutter日期选择器插件textfield_datepicker的使用
Flutter日期选择器插件textfield_datepicker的使用
标题
flutter日期选择器插件textfield_datepicker的使用
内容
A collection of three flutter widget TextfieldDatePicker, TextFieldDateAndTimePicker and TextFieldTimePicker. These widgets gives you access to the various platform date and time pickers based on your device platform.
The date or time picked is shown in a Material TextFormField widget. These three widgets earlier mentioned gives you access to most of Material TextFormField parameters allowing you to design your textfield based on your preference
Screenshots of how it works For screenshots of how this package works, visit this link See example for details of how this package works
Installation Add the textfield_datepicker package to your pubspec.yml file.
Import the package into your dart file
Usage
TextfieldDatePicker
Property | Default | Description |
---|---|---|
materialDatePickerInitialEntryMode | DatePickerEntryMode.calendar | In DatePickerEntryMode.calendar mode, a calendar grid is displayed and the user taps the day they wish to select. In DatePickerEntryMode.input mode a TextField is displayed and the user types in the date they wish to select… |
materialDatePickerFirstDate | required | The earliest allowable date. |
materialDatePickerInitialDate | required | When the date picker is first displayed, it will show the month of materialDatePickerInitialDate, with materialDatePickerInitialDate selected. |
materialDatePickerLastDate | required | The latest allowable date. |
preferredDateFormat | required | The parameter is for formatting and parsing dates in a locale-sensitive manner. |
materialDatePickerBuilder | optional | The parameter can be used to wrap the dialog widget to add inherited widgets like Theme. |
materialDatePickerLocale | optional | The optional locale argument can be used to set the locale for the date picker. It defaults to the ambient locale provided by Localizations. |
materialDatePickerSelectableDayPredicate | optional | An optional function can be passed in to only allow certain days for selection. |
cupertinoDatePickerMaximumDate | required | The maximum selectable date that the picker can settle on. |
cupertinoDatePickerMinimumDate | required | The minimum selectable date that the picker can settle on. |
cupertinoDatePickerMinimumYear | optional | The minimum year that the picker can be scrolled to in CupertinoDatePickerMode.date mode. Defaults to 1 and must not be null. |
cupertinoDatePickerMaximumYear | required | The minimum year that the picker can be scrolled to in CupertinoDatePickerMode.date mode. Defaults to 1 and must not be null. |
cupertinoDatePickerBackgroundColor | required | Defaults to null, which disables background painting entirely. Background color of cupertinoDatePicker. |
cupertinoDatePickerKey | optional | The is an identifier. |
cupertinoDateInitialDateTime | required | Defaults to the present date and time and must not be null. |
cupertinoDateOrder | optional | Determines the order of the columns inside CupertinoDatePicker in date mode. Defaults to the locale’s default date format/order. |
textFieldDatePickerWidth | optional | Gives you the option to adjust the width of the TextfieldDatePicker widget. |
textFieldDatePickerMargin | optional | Allows you to add some margin to the TextfieldDatePicker. |
textFieldDatePickerPadding | optional | Allows you to add some padding to the TextfieldDatePicker. |
TextFieldDateAndTimePicker
Property | Default | Description |
---|---|---|
materialDatePickerInitialEntryMode | DatePickerEntryMode.calendar | In DatePickerEntryMode.calendar mode, a calendar grid is displayed and the user taps the day they wish to select. In DatePickerEntryMode.input mode a TextField is displayed and the user types in the date they wish to select… |
materialDatePickerFirstDate | required | The earliest allowable date. |
materialDatePickerInitialDate | required | When the date picker is first displayed, it will show the month of materialDatePickerInitialDate, with materialDatePickerInitialDate selected. |
materialDatePickerLastDate | required | The latest allowable date. |
preferredDateFormat | required | The parameter is for formatting and parsing dates in a locale-sensitive manner. |
materialDatePickerBuilder | optional | The parameter can be used to wrap the dialog widget to add inherited widgets like Theme. |
materialDatePickerLocale | optional | The optional locale argument can be used to set the locale for the date picker. It defaults to the ambient locale provided by Localizations. |
materialDatePickerSelectableDayPredicate | optional | An optional function can be passed in to only allow certain days for selection. |
materialDatePickerUse24hrFormat | optional | Defaults to false. |
materialDatePickerInitialEntryMode | optional | The parameter can be used to determine the initial time entry selection of the picker (either a clock dial or text input). |
materialDatePickerBuilder | optional | The parameter can be used to wrap the dialog widget to add inherited widgets like Localizations.override, Directionality, or MediaQuery. |
cupertinoDatePickerMaximumDate | required | The maximum selectable date that the picker can settle on. |
cupertinoDatePickerMinimumDate | required | The minimum selectable date that the picker can settle on. |
cupertinoDatePickerMinimumYear | optional | The minimum year that the picker can be scrolled to in CupertinoDatePickerMode.date mode. Defaults to 1 and must not be null. |
cupertinoDatePickerMaximumYear | required | The minimum year that the picker can be scrolled to in CupertinoDatePickerMode.date mode. Defaults to 1 and must not be null. |
cupertinoDatePickerBackgroundColor | required | Defaults to null, which disables background painting entirely. Background color of cupertinoDatePicker. |
cupertinoDatePickerKey | optional | The is an identifier. |
cupertinoDateInitialDateTime | required | Defaults to the present date and time and must not be null. |
cupertinoDateOrder | optional | Determines the order of the columns inside CupertinoDatePicker in date mode. Defaults to the locale’s default date format/order. |
cupertinoTimePickerUse24hFormat | optional | Defaults to false. |
cupertinoTimePickerMinuteInterval | optional | The granularity of the minutes spinner, if it is shown in the current mode. Must be an integer factor of 60. |
textFieldDateTimePickerWidth | optional | Gives you the option to adjust the width of the TextfieldDateAndTimePicker widget. |
textFieldDateTimePickerMargin | optional | Allows you to add some margin to the TextfieldDateAndTimePicker. |
textFieldDateTimePickerPadding | optional | Allows you to add some padding to the TextfieldDateAndTimePicker. |
TextFieldTimePicker
Property | Default | Description |
---|---|---|
materialInitialTime | required | When the time picker is first displayed, it will have materialInitialTime, as the time selected. |
materialTimePickerUse24hrFormat | optional | Defaults to false. |
materialTimePickerInitialEntryMode | optional | The parameter can be used to determine the initial time entry selection of the picker (either a clock dial or text input). |
materialTimePickerBuilder | optional | The parameter can be used to wrap the dialog widget to add inherited widgets like Localizations.override, Directionality, or MediaQuery. |
cupertinoDatePickerBackgroundColor | required | Defaults to null, which disables background painting entirely. Background color of cupertinoDatePicker. |
cupertinoDatePickerKey | optional | The is an identifier. |
cupertinoDateInitialDateTime | required | Defaults to the present date and time and must not be null. |
cupertinoTimePickerUse24hFormat | optional | Defaults to false. |
cupertinoTimePickerMinuteInterval | optional | The granularity of the minutes spinner, if it is shown in the current mode. Must be an integer factor of 60. |
textFieldTimePickerWidth | optional | Gives you the option to adjust the width of the TextfieldTimePicker widget. |
textFieldTimePickerMargin | optional | Allows you to add some margin to the TextfieldTimePicker. |
textFieldTimePickerPadding | optional | Allows you to add some padding to the TextfieldTimePicker. |
示例代码
import 'package:example/screens/textfieldDatePicker1.dart';
import 'package:example/screens/textfieldDateTimePicker.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Textfield Date Picker Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: WelcomePage.routeName,
routes: {
TextFieldDatePickerDemo.routeName: (context) =>
const TextFieldDatePickerDemo(),
TextFieldDateTimePicker.routeName: (context) =>
const TextFieldDateTimePicker()
},
);
}
}
安装
在你的 pubspec.yml
文件中添加 textfield_datepicker
包。
dependencies:
textfield_datepicker: ^0.2.0
使用
import 'package:textfield_datepicker/textfield_datepicker.dart';
import 'package:textfield_datepicker/textfield_timePicker.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Textfield Date Picker Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TextFieldDatePickerDemo(),
);
}
}
更多关于Flutter日期选择器插件textfield_datepicker的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html