Home > Software engineering >  facing problem using DatePicker in flutter
facing problem using DatePicker in flutter

Time:10-07

I am using DatePicker from package:date_picker_timeline

here I want to set start date:-30 days of current date and end date: 30 days of current date

and It should be shown current date when I start app..I mean showing today date and I can be able to move and forward upto 30 days

I am failing to finding regarding properties, and it should be shown current date with selected when app starts...

DateTime.now(),
                initialSelectedDate:DateTime.now(),
                selectionColor: Colors.blue,
                monthTextStyle: TextStyle(fontSize: 12),
                onDateChange: (DateTime date) {
                  setState(() {
                    selecteddate = date;
                    //print("Selected Date is :" selecteddate.toString());
                  });
                },
              ),

CodePudding user response:

You can take help from activeDates parameter,

DatePicker(
  DateTime.now().subtract(Duration(days: 30)),
  activeDates: List.generate(
      60,
      (index) => (DateTime.now().subtract(Duration(days: 30)))
          .add(Duration(days: index))),
  initialSelectedDate: DateTime.now(),
  selectionColor: Colors.black,
  selectedTextColor: Colors.white,
  onDateChange: (date) {},
),
  • Related