Building a Flutter DateTime Picker in just 15 minutes

Learn implementation of an iOS-style DateTime Picker in Flutter

Shivam Goyal
Jul 17, 2019 · 4 min read

Introduction

With the Flutter DateTime Picker plugin, you can add date & time pickers to your native application. The plugin’s interface is inspired by the iOS Cupertino style menu.

In this tutorial, you’ll build a mobile app featuring a DateTime Picker using the Flutter SDK. Your app will:

  • Display separate Date & Time Pickers with a minimalistic interface
  • Display the selected data as outputs to console
That’s how our DateTime Picker gonna look

This tutorial focuses on adding a DateTime Picker to a Flutter app. Non-relevant concepts and code blocks are glossed over and are provided for you to simply copy and paste.


Setting up Flutter on your machine

The detailed steps to install Flutter on your personal computer & getting started with Flutter is available at the following blog

Coding the component

The basic format of a DateTime Picker looks like the one below:

Adding additional capability to a Flutter app is easy using Pub packages. In this tutorial, you introduce the DateTime Picker plugin by adding a single line to the pubspec.yaml file.

Import flutter_datetime_picker dependency to your main.dart file by adding the following line at the starting of the file:

Amend your main.dart file as per the following code:

  • Connect your Emulator or physical Android device to test the application.
  • Click on Build & Run.
  • And Boooom, your app is ready.
    The final build would look like the below illustration.
The final output of the implementation

Customization Options

There are three functional variations of the plugin available as follows:

  • Solo DatePicker
  • Solo TimePicker
  • Dual DateTimePicker

There are various language options available to implement the plugin for international use. For changing the language of the component amend the following with preferred LocaleType.

locale: LocaleType.en
  • English(en)
  • Persian(fa)
  • Chinese(zh)
  • Dutch(nl)
  • Russian(ru)
  • Italian(it)
  • French(fr)
  • Spanish(es)
  • Polish (pl)
  • Portuguese(pt)
  • Korean(ko)
  • Arabic(ar)
  • Turkish(tr)
  • Japanese(jp)
  • German(de)
  • Danish(da)
  • Bengali(bn)
  • Vietnamese(vi)
  • Armenian(hy)

If you want to customize your own style of date time picker, there is a class called CommonPickerModel, every type of date time picker is extended from this class, you can refer to other picker models (eg. DatePickerModel), and write your custom one, then pass this model to showPicker method, so that your own date time picker will appear, it’s easy, and will perfectly meet your demand.

How to customize your own picker model:



🎯 That’s all for today.

If you got any queries hit me up in the comments or ping me over on hi@itsshivam.com 📧

If you learned even a thing or two, clap your hands👏 as many times as you can to show your support! It really motivates me to contribute towards the community.

Feeling too generous? Buy me a Drink 🍺

Wanna collaborate? Let’s talk some tech 😊

Stalk me over on itsshivam.com, GitHub, or LinkedIn. 👀

Enappd

App starters, Themes, Templates, Complete Web and Mobile…

Shivam Goyal

Written by

👨‍💻 Flutter Dev & Facilitator | Microsoft Student Partner | Tech Blogger | 👨‍👧‍👦 MLH Organizer | 🌐 itsshivam.com

Enappd

Enappd

App starters, Themes, Templates, Complete Web and Mobile Apps Solutions

More From Medium

More on App Development from Enappd

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade