DEV Community


Posted on

Creating a Date Picker #Flutter

this tutorial focuses on adding a Date Picker to a Flutter app.

so let's do this...

we will first create a simple button on which we can press and get our date picker pop.

    child: Text("Date: " + selectedDate.toString()),
    onPressed: () async{
        DateTime date = await showDatePicker(
        context: context, 
        firstDate: DateTime(2010), 
        lastDate: 1)));

        if (date != null){
                selectedDate = date;
Enter fullscreen mode Exit fullscreen mode

here, the initialDate represents the current selected date, firstDate represents the date from where your calendar will start and the lastDate represents the ending date of your calendar.

you can even use it's "then" function to get the value selected from that picker.

so that's it go and try.

Top comments (0)