DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Parth
Parth

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.

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

        if (date != null){
            setState((){
                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)

Find what you were looking for? Sign up so you can:

Β 
🌚 Enable dark mode
πŸ”  Change your default font
πŸ“š Adjust your experience level to see more relevant content