YSTools.dart 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. class YSDatePicker extends StatefulWidget {
  4. final ValueSetter<String> choose;
  5. const YSDatePicker({Key key, this.choose}) : super(key: key);
  6. @override
  7. _YSDatePickerState createState() => _YSDatePickerState();
  8. }
  9. class _YSDatePickerState extends State<YSDatePicker> {
  10. String birthday = DateTime.now().year.toString()+'-'+DateTime.now().month.toString()+'-'+DateTime.now().day.toString();
  11. @override
  12. Widget build(BuildContext context) {
  13. return Container(
  14. color: Colors.transparent,
  15. height: 340,
  16. child: Column(
  17. crossAxisAlignment: CrossAxisAlignment.end,
  18. children: [
  19. CupertinoButton(
  20. padding: EdgeInsets.all(0),
  21. child: Container(
  22. height: 20,
  23. child: Image.asset('lib/images/off.png'),
  24. ),
  25. onPressed: (){
  26. Navigator.pop(context);
  27. },
  28. ),
  29. Container(
  30. height: 240,
  31. padding: EdgeInsets.all(10),
  32. decoration: BoxDecoration(
  33. color: Colors.white,
  34. borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20))
  35. ),
  36. child: CupertinoDatePicker(
  37. initialDateTime: DateTime.now(),
  38. onDateTimeChanged: (date) {
  39. birthday = date.year.toString()+'/'+date.month.toString()+'/'+date.day.toString();
  40. },
  41. mode: CupertinoDatePickerMode.date,
  42. ),
  43. ),
  44. Container(
  45. height: 56,
  46. width: MediaQuery.of(context).size.width,
  47. color: Colors.white,
  48. child: CupertinoButton(
  49. padding: EdgeInsets.all(0),
  50. child: Container(
  51. height: 30,
  52. width: 80,
  53. decoration: BoxDecoration(
  54. color: Colors.white,
  55. borderRadius: BorderRadius.all(Radius.circular(15)),
  56. boxShadow: [
  57. BoxShadow(color: Colors.grey,blurRadius: 3)
  58. ]
  59. ),
  60. child: Text('确定',style: TextStyle(fontSize: 14,color: Color(0xFF4CC17C),decoration: TextDecoration.none,fontWeight: FontWeight.normal)),
  61. alignment: Alignment.center,
  62. ),
  63. onPressed: (){
  64. Navigator.pop(context);
  65. widget.choose(birthday);
  66. },
  67. ),
  68. alignment: Alignment.center,
  69. )
  70. ],
  71. ),
  72. );
  73. }
  74. }