simpleDatePicker static method
Future
simpleDatePicker(
- BuildContext context, {
- bool barrierDismissible = true,
- double height = 500,
- double width = 400,
- int needYear = 110,
- double vGap = 16,
- BoxDecoration? pickerDecoration,
- DateModel? startDate,
- DateModel? endDate,
- double pickerVisibilityHeight = 140,
- double itemHeight = 40,
- double itemWidth = 100,
- double maskHeight = 40,
- double maskRadius = 0,
- int backwardYear = 50,
- Color? maskColor = const Color.fromRGBO(242, 242, 244, 0.7),
- Duration duration = const Duration(milliseconds: 500),
- Curve curve = Curves.easeInOutCubic,
- dynamic callBack()?,
展示选择器基础示例,不满足样式外部可自定义。
Implementation
static Future<dynamic> simpleDatePicker(
BuildContext context,
{bool barrierDismissible = true,
double height = 500,
double width = 400,
int needYear = 110,
double vGap = 16,
BoxDecoration? pickerDecoration,
DateModel? startDate,
DateModel? endDate,
double pickerVisibilityHeight = 140,
double itemHeight = 40,
double itemWidth = 100,
double maskHeight = 40,
double maskRadius = 0,
int backwardYear = 50,
Color? maskColor = const Color.fromRGBO(242, 242, 244, 0.7),
Duration duration = const Duration(milliseconds: 500),
Curve curve = Curves.easeInOutCubic,
Function(DateModel? startDate, DateModel? endDate)? callBack}) {
final controller = DateController();
return showDialog(
context: context,
barrierDismissible: barrierDismissible,
builder: (context) {
return DatePicker(
controller: controller,
pickerDecoration: pickerDecoration,
width: width,
height: height,
needYear: needYear,
startDate: startDate,
endDate: endDate,
backwardYear: backwardYear,
vGap: vGap,
pickerVisibilityHeight: pickerVisibilityHeight,
itemHeight: itemHeight,
itemWidth: itemWidth,
maskHeight: maskHeight,
maskRadius: maskRadius,
maskColor: maskColor,
duration: duration,
curve: curve,
startWidget: const Padding(
padding: EdgeInsets.only(left: 20),
child: Text('开始日期:',
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold)),
),
endWidget: const Padding(
padding: EdgeInsets.only(left: 20),
child: Text('结束日期:',
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold)),
),
yearBuilder: (year) {
return Center(
child: Text(
"$year年",
style: const TextStyle(
color: Color.fromRGBO(21, 21, 21, 1),
fontSize: 16,
fontWeight: FontWeight.bold)
),
);
},
monthBuilder: (month) {
return Container(
alignment: Alignment.center,
child: Text(
"$month月",
style: const TextStyle(
color: Color.fromRGBO(21, 21, 21, 1),
fontSize: 16,
fontWeight: FontWeight.bold)
),
);
},
dayBuilder: (day) {
return Container(
alignment: Alignment.center,
child: Text(
"$day日",
style: const TextStyle(
color: Color.fromRGBO(21, 21, 21, 1),
fontSize: 16,
fontWeight: FontWeight.bold)
),
);
},
action: GestureDetector(
onTap: () {
final startDate = controller.getStartDate();
final endDate = controller.getEndDate();
callBack?.call(startDate, endDate);
Navigator.pop(context, [startDate, endDate]);
},
child: Center(
child: Container(
margin: const EdgeInsets.only(top: 30),
padding:
const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
decoration: BoxDecoration(
color: Colors.lightBlueAccent,
borderRadius: BorderRadius.circular(20),
),
child: const Text("确定",
style: TextStyle(color: Colors.white, fontSize: 16)),
)),
),
);
});
}