0

I want to get only selected date from tablecalender, but it gives me this output

2021-08-18 12:00:00.000Z

here is tablecalender code


  final dateFormat = DateFormat('yyyy-MMMM-dd');
  DateTime _chosenDate = DateTime.now();
child: TableCalendar(  
              calendarController: _controller, 
              initialSelectedDay: _chosenDate,
              initialCalendarFormat: CalendarFormat.month,  
              calendarStyle: CalendarStyle(
              canEventMarkersOverflow: true,
              markersColor: Colors.white,
              weekdayStyle: TextStyle(color: Colors.blue[900]),
            
              
              todayColor: Colors.white54,
              todayStyle: TextStyle(color: Colors.blue[900], fontSize: 15, fontWeight: FontWeight.bold),
              selectedColor: Colors.blue[900],
              outsideWeekendStyle: TextStyle(color: Colors.blue[900]),
              outsideStyle: TextStyle(color: Colors.blue[900]),
              weekendStyle: TextStyle(color: Colors.blue[900]),
              renderDaysOfWeek: false,),  
              onCalendarCreated: (date,event,_){                             
              },
              onDaySelected: (date, event,_) {                 
                setState(() {
                 _chosenDate = date;
                  print("_chosenDate");
                  print(_chosenDate);                  
                });               
              },            
            ));  
            
  }

i tried to use split method, but it is not accessible

please help how to get only date (2021-08-18) using tablecalender

TimeToCode
  • 1,458
  • 3
  • 18
  • 60

1 Answers1

0

in print replace _chosenDate with "${_chosenDate.toString().split(" ").first}"

Ruchit
  • 2,137
  • 1
  • 9
  • 24