import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class YSDatePicker extends StatefulWidget { final ValueSetter choose; const YSDatePicker({Key key, this.choose}) : super(key: key); @override _YSDatePickerState createState() => _YSDatePickerState(); } class _YSDatePickerState extends State { String birthday = DateTime.now().year.toString()+'-'+DateTime.now().month.toString()+'-'+DateTime.now().day.toString(); @override Widget build(BuildContext context) { return Container( color: Colors.transparent, height: 340, child: Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ CupertinoButton( padding: EdgeInsets.all(0), child: Container( height: 20, child: Image.asset('lib/images/off.png'), ), onPressed: (){ Navigator.pop(context); }, ), Container( height: 240, padding: EdgeInsets.all(10), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20)) ), child: CupertinoDatePicker( initialDateTime: DateTime.now(), onDateTimeChanged: (date) { birthday = date.year.toString()+'/'+date.month.toString()+'/'+date.day.toString(); }, mode: CupertinoDatePickerMode.date, ), ), Container( height: 56, width: MediaQuery.of(context).size.width, color: Colors.white, child: CupertinoButton( padding: EdgeInsets.all(0), child: Container( height: 30, width: 80, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(15)), boxShadow: [ BoxShadow(color: Colors.grey,blurRadius: 3) ] ), child: Text('确定',style: TextStyle(fontSize: 14,color: Color(0xFF4CC17C),decoration: TextDecoration.none,fontWeight: FontWeight.normal)), alignment: Alignment.center, ), onPressed: (){ Navigator.pop(context); widget.choose(birthday); }, ), alignment: Alignment.center, ) ], ), ); } }