Jor*_*ira 1 datepicker dart flutter
我想知道是否有可能只有月份和年份的选择器,而对于当前的DatePicker,我没有找到此选项。
先感谢您。
小智 8
将flutter_datetime_picker与自定义模型一起使用,该模型禁用最后一列
class CustomMonthPicker extends DatePickerModel {
CustomMonthPicker({DateTime currentTime, DateTime minTime, DateTime maxTime,
LocaleType locale}) : super(locale: locale, minTime: minTime, maxTime:
maxTime, currentTime: currentTime);
@override
List<int> layoutProportions() {
return [1, 1, 0];
}
}
Run Code Online (Sandbox Code Playgroud)
并显示带有自定义模型的选择器
DatePicker.showPicker(context,
...
pickerModel: CustomMonthPicker(
minTime: DateTime(2020, 1, 1),
maxTime: DateTime.now(),
currentTime: DateTime.now()
)
...
)
Run Code Online (Sandbox Code Playgroud)
您可以使用该YearPicker小部件仅显示年度日历。一个典型的例子是:
TextFormField(
validator: value.isEmpty ? 'this field is required' : null,
readOnly: true,
style: TextStyle(fontSize: 13.0),
decoration: InputDecoration(
hintStyle: TextStyle(fontSize: 13.0),
hintText: 'Pick Year',
contentPadding: EdgeInsets.symmetric(horizontal: 10.0),
border: OutlineInputBorder(),
suffixIcon: Icon(Icons.calendar_today),
),
onTap: () => handleReadOnlyInputClick(context),
)
void handleReadOnlyInputClick(context) {
showBottomSheet(
context: context,
builder: (BuildContext context) => Container(
width: MediaQuery.of(context).size.width,
child: YearPicker(
selectedDate: DateTime(1997),
firstDate: DateTime(1995),
lastDate: DateTime.now(),
onChanged: (val) {
print(val);
Navigator.pop(context);
},
),
)
);
}
Run Code Online (Sandbox Code Playgroud)
注意:您不必使用 a bottomSheet,您可以将其嵌套在小部件有效的任何位置。
| 归档时间: |
|
| 查看次数: |
2463 次 |
| 最近记录: |