I want to get output expiration date to use, but unfortunately I got wrong result not pass to next month, if i input 31 days.

Select Date

Output result expiration date

Code: I calulate expiration date

  void initState() {
    _controller = AnimationController(vsync: this);

    var date = new DateTime.now().toString();

    var dateParse = DateTime.parse(date);

    var formattedDate31day = "Time ${dateParse.hour}:${dateParse.minute} Date ${dateParse.day + 31}-${dateParse.month}-${dateParse.year}";

    setState(() {
      finalDate31Day = formattedDate31day.toString();


widget output result:

  Widget _expirationDate(){
    if(_selectedDateVal == day['1']){
      return Text('Expiration: $finalDate31Day', style: TextStyle(fontSize: 20.0));

      return Container();

Solution 1: Dmytro Rostopira

I have no idea, what the reason behind converting DateTime to string and then parsing it back, so I will ignore this:

  var date = DateTime.now().add(Duration(days: 31));
  var formattedDate31day = "Time ${date.hour}:${date.minute} Date ${date.day}-${date.month}-${date.year}";
  setState(() {
    finalDate31Day = formattedDate31day;