Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class InlinePicker extends StatefulWidget {
- @override
- _InlinePickerState createState() => _InlinePickerState();
- }
- class _InlinePickerState extends State<InlinePicker> {
- DateTime _initial;
- DateTime _selectedDate;
- @override
- void initState() {
- _initial = DateTime.now().subtract(new Duration(days: 7));
- _selectedDate = _initial;
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Container(
- child: GestureDetector(
- onTap: () async {
- var date = await pick();
- if (date != null) {
- // todo: validate
- if (date != null)
- setState(() {
- _selectedDate = date;
- });
- }
- },
- child: new Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Text("To", style: style),
- Text(DateFormat.yMMMd().format(_selectedDate), style: style)
- ],
- ),
- Align(
- alignment: Alignment.centerRight,
- child: Icon(
- Icons.arrow_drop_down,
- color: Color.fromRGBO(58, 182, 255, 1),
- // size: 25.0,
- ),
- )
- ]),
- ),
- );
- }
- static const style = TextStyle(
- fontSize: 15.0,
- fontFamily: 'BPreplay',
- color: Colors.white,
- );
- Future<DateTime> pick() {
- return showDatePicker(
- context: context,
- initialDate: DateTime.now(),
- firstDate: _initial,
- lastDate: DateTime(2030),
- builder: (BuildContext context, Widget child) {
- return Theme(
- data: ThemeData.dark(),
- child: child,
- );
- },
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement