Advertisement
Guest User

Untitled

a guest
Mar 11th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.90 KB | None | 0 0
  1.  
  2. class InlinePicker extends StatefulWidget {
  3.   @override
  4.   _InlinePickerState createState() => _InlinePickerState();
  5. }
  6.  
  7. class _InlinePickerState extends State<InlinePicker> {
  8.   DateTime _initial;
  9.   DateTime _selectedDate;
  10.  
  11.   @override
  12.   void initState() {
  13.     _initial = DateTime.now().subtract(new Duration(days: 7));
  14.     _selectedDate = _initial;
  15.     super.initState();
  16.   }
  17.  
  18.   @override
  19.   Widget build(BuildContext context) {
  20.     return Container(
  21.       child: GestureDetector(
  22.         onTap: () async {
  23.           var date = await pick();
  24.  
  25.           if (date != null) {
  26.             // todo: validate
  27.             if (date != null)
  28.               setState(() {
  29.                 _selectedDate = date;
  30.               });
  31.           }
  32.         },
  33.         child: new Row(
  34.             mainAxisAlignment: MainAxisAlignment.center,
  35.             children: <Widget>[
  36.               Column(
  37.                 mainAxisSize: MainAxisSize.min,
  38.                 children: <Widget>[
  39.                   Text("To", style: style),
  40.                   Text(DateFormat.yMMMd().format(_selectedDate), style: style)
  41.                 ],
  42.               ),
  43.               Align(
  44.                 alignment: Alignment.centerRight,
  45.                 child: Icon(
  46.                   Icons.arrow_drop_down,
  47.                   color: Color.fromRGBO(58, 182, 255, 1),
  48.                   // size: 25.0,
  49.                 ),
  50.               )
  51.             ]),
  52.       ),
  53.     );
  54.   }
  55.  
  56.   static const style = TextStyle(
  57.     fontSize: 15.0,
  58.     fontFamily: 'BPreplay',
  59.     color: Colors.white,
  60.   );
  61.  
  62.   Future<DateTime> pick() {
  63.     return showDatePicker(
  64.       context: context,
  65.       initialDate: DateTime.now(),
  66.       firstDate: _initial,
  67.       lastDate: DateTime(2030),
  68.       builder: (BuildContext context, Widget child) {
  69.         return Theme(
  70.           data: ThemeData.dark(),
  71.           child: child,
  72.         );
  73.       },
  74.     );
  75.   }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement