Created
July 31, 2020 08:29
-
-
Save sooorajjj/e4197bf885f9f0cdf3109bb9dc2337e6 to your computer and use it in GitHub Desktop.
reverse datepicker in Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:date_picker_timeline/date_picker_timeline.dart'; | |
import 'package:route_map/constants.dart'; | |
class HistoryPage extends StatefulWidget { | |
@override | |
_HistoryPageState createState() => _HistoryPageState(); | |
} | |
class _HistoryPageState extends State<HistoryPage> { | |
final startDate = DateTime(2020, 07, 14); | |
DateTime _selectedValue = DateTime.now(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("History"), | |
), | |
body: Container( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: <Widget>[ | |
Container( | |
child: DatePicker( | |
DateTime.now() | |
.subtract(Duration(days: _calculateDays(startDate))), | |
daysCount: _calculateDays(startDate) + 1, | |
width: 60, | |
height: 80, | |
initialSelectedDate: DateTime.now(), | |
selectionColor: kPrimaryColor, | |
selectedTextColor: Colors.white, | |
onDateChange: (date) { | |
// New date selected | |
setState(() { | |
_selectedValue = date; | |
}); | |
}, | |
), | |
), | |
], | |
), | |
)); | |
} | |
int _calculateDays(var startDate) { | |
final today = DateTime.now(); | |
final difference = today.difference(startDate).inDays; | |
print(difference); | |
return difference; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment