CalendarPicker 日历选择器
代码演示
import 'package:antd_flutter_example/demo_block.dart';
import 'package:flutter/cupertino.dart';
import 'package:trionesdev_antd_mobile/trionesdev_antd_mobile.dart';
class CalendarPickerPage extends StatefulWidget {
const CalendarPickerPage({super.key});
@override
State<StatefulWidget> createState() => _CalendarPickerPageState();
}
class _CalendarPickerPageState extends State<CalendarPickerPage> {
@override
Widget build(BuildContext context) {
return AntScaffold(
appBar: AntAppBar(
title: Text("CalendarPicker"),
),
body: SingleChildScrollView(
child: Column(
children: [
DemoBlock(
title: "基本用法",
child: Column(
children: [
AntButton(
text: "基本用法",
onPressed: () {
showAntCalendarPicker(
context: context,
onOk: (value) {
AntToast.show(
context: context, content: Text("$value"));
});
},
),
],
),
),
DemoBlock(
title: "设置默认值",
child: Column(
children: [
AntButton(
text: "设置默认值",
onPressed: () {
showAntCalendarPicker(
context: context,
value: DateTime.now(),
onOk: (value) {
AntToast.show(
context: context, content: Text("$value"));
});
},
),
],
),
),
DemoBlock(
title: "基本用法(范围选择)",
child: Column(
children: [
AntButton(
text: "基本用法",
onPressed: () {
showAntCalendarRangePicker(
context: context,
onOk: (value) {
AntToast.show(
context: context,
content: Text(
"${value?.elementAtOrNull(0)}~${value?.elementAtOrNull(1)}"));
});
},
),
],
),
),
DemoBlock(
title: "设置默认值(范围选择)",
child: Column(
children: [
AntButton(
text: "设置默认值",
onPressed: () {
showAntCalendarRangePicker(
context: context,
value: [
DateTime.now(),
DateTime.now().add(Duration(days: 7))
],
onOk: (value) {
showAntToast(
context: context,
content: Text(
"${value?.elementAtOrNull(0)}~${value?.elementAtOrNull(1)}"));
});
},
),
],
),
),
],
),
),
);
}
}
API
日历选择器 showAntCalendarPicker
属性 | 说明 | 类型 | 默认值 |
---|---|---|---|
value | 当前值 | DateTime? | DateTime.now() |
onOk | 确定按钮回调 | ValueChanged<DateTime?>? |
日历区间选择器 showAntCalendarRangePicker
属性 | 说明 | 类型 | 默认值 |
---|---|---|---|
value | 当前值 | List<DateTime>? | |
onOk | 确定按钮回调 | ValueChanged<List<DateTime?>?>? |