Flutter DateField and DateFormField

Overview

date_field

pub package

Contains DateTimeField and DateTimeFormField which allows the user to pick a DateTime from an input field! Depending on the mode, it can ask the user the time, the date or both at the same time ;) !

Usage

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  date_field: ^2.1.2

In your library add the following import:

import 'package:date_field/date_field.dart';

Getting Started

There are two widgets in this package:

  • DateTimeField
  • DateTimeFormField

It follows the usual Flutter patterns convention, meaning the DateTimeFormField extends the FormField widget and wraps a DateTimeField widget.

You can customize both of these widgets with the decoration argument which is fully supported.

You can also specify whether you would like to ask the user for a date, a time or both using the mode parameter.

Example

The following picture illustrates some things you can do with this package.

DateTimeFormField(
  decoration: const InputDecoration(
    hintStyle: TextStyle(color: Colors.black45),
    errorStyle: TextStyle(color: Colors.redAccent),
    border: OutlineInputBorder(),
    suffixIcon: Icon(Icons.event_note),
    labelText: 'Only time',
  ),
  mode: DateTimeFieldPickerMode.time,
  autovalidateMode: AutovalidateMode.always,
  validator: (e) => (e?.day ?? 0) == 1 ? 'Please not the first day' : null,
  onDateSelected: (DateTime value) {
    print(value);
  },
),

You can check the GitHub repo for a complete example.

Comments
  • initial date is not greater than or equal to minimumDate

    initial date is not greater than or equal to minimumDate

    Hello, I am using the latest Flutter 2.10.3 and Dart SDK is 2.16.1 and I am using the Getx State Management when I click on the date field I am getting this exception the initial date is not greater than or equal to minimumDate Thank you :)

    opened by NikhilKukreja26 6
  • Remove date or set back to empty

    Remove date or set back to empty

    Hi You got very good plugin for date time, I am facing an issue after adding date to field there is no way to remove or set it back to empty field. please help me on this

    opened by JandalZaheer 5
  • Overrideable Picker Definitions

    Overrideable Picker Definitions

    I love the flexibility of this input field but needed to take it a smidge further. I have a business requirement where I need to restricts the date and time input ranges, and even specify the minute increments.

    To achieve this, I need to tweak the core implementation of showMaterialTimePicker. But to that point, I still want to leverage everything date_field has to offer.

    Buy using the new Constructor Tear-offs, and making the showCuppertino... and showMaterial... pickers override-able methods, I can create Child classes that tweak the pickers before show to meet my requirements.

    opened by axrs 4
  • DateTimeFormField doesn't update

    DateTimeFormField doesn't update

    Widget doesn't change its content on rebuild when initialValue changes to null.

    DateTimeFormField(
                                    decoration: InputDecoration(
                                      hintStyle: const TextStyle(color: Colors.black45),
                                      errorStyle: const TextStyle(color: Colors.redAccent),
                                      border: const OutlineInputBorder(),
                                      suffixIcon: IconButton(
                                        icon: const Icon(Icons.cancel),
                                        onPressed: () {
                                          _bloc.change(
                                            kontener.copyWith(
                                              dataW: null,
                                            ),
                                          );
                                        },
                                      ),
                                      labelText: 'Data przypisania',
                                    ),
                                    initialValue: kontener.dataW,
                                    dateFormat: DateFormat.yMMMEd('pl_PL'),
                                    mode: DateTimeFieldPickerMode.date,
                                    onDateSelected: (value) {
                                      _bloc.change(
                                        kontener.copyWith(dataW: value),
                                      );
                                    },
                                    validator: (value) => value == null ? 'Wybierz datę' : null,
                                  )),
    
    opened by danw8989 4
  • DateTimeField should be a statelesswidget

    DateTimeField should be a statelesswidget

    similar to #2 where datetimeformfield was a statelesswidget... I think datetimefield should be a statefulwidget as well... I see that in the example there's a datetimefield as a child of a statefulwidget and it sets the state of its parent, which if I intuit currectly causes the parent to be rebuilt along with the datetimefield. So in a stateful context you can make it update that way, but it would be much nicer if it already did that on its own. So I guess it would make sense to make it a statefulwidget and to setState along with calling the onDateChanged

    opened by NANASHI0X74 4
  • Initial dateTime is not selected properly

    Initial dateTime is not selected properly

    When I have lastDate provided (e.g. user should have 18 years), initialDateTime would be set to DateTime.now(), which causes errors. Current workaround is to provide initialDate in correct range, but this means date field would be preselected.

    This issue can be solved by changing the default initial date value from DateTime.now() to lastDate.

    So, this would be the correct code: final DateTime initialDateTime = selectedDate ?? lastDate; , on line 86, function _selectDate, in file field.dart.

    From my limited testing, this would not cause any additional issues.

    If there is another way to solve this issue, please let me know.

    opened by Ranko97 3
  • Calendar hard to see in Darkmode on iOS

    Calendar hard to see in Darkmode on iOS

    I'm not sure if I'm doing something wrong here, but I've got an app using DateTimeFormField (3.0.1) on iOS. The app is dark mode-only and when you click into the date field it looks like it's adding a grey overlay over the entire screen (including the date picker) which makes the date picker very faint and difficult to read. I don't see this same thing on light mode.

    toodark

    Here is what I'm currently setting for my Theme:

    import 'package:flutter/material.dart';
    
    final ThemeData darkTheme = _buildDarkTheme();
    
    ThemeData _buildDarkTheme() {
      final ThemeData base = ThemeData.dark();
      return base.copyWith(
        colorScheme: base.colorScheme.copyWith(
          primary: const Color.fromARGB(255, 40, 203, 162),
          onPrimary: const Color.fromARGB(255, 40, 101, 85),
          secondary: Colors.amber,
          error: Colors.red,
        ),
      );
    }
    
    class App extends StatelessWidget {
      const App({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Barreleye',
          theme: barreleyeDarkTheme,
          darkTheme: barreleyeDarkTheme,
          themeMode: ThemeMode.dark,
          home: const OperationList(),
        );
      }
    }
    

    And my invocation of the DateTimeFormField.

        fields.add(DateTimeFormField(
          decoration: const InputDecoration(
            //border: OutlineInputBorder(),
            suffixIcon: Icon(Icons.event_note),
            labelText: 'Ticket Date',
          ),
          initialValue: _date,
          enabled: _enableEditing,
          mode: DateTimeFieldPickerMode.dateAndTime,
          autovalidateMode: AutovalidateMode.always,
          validator: (DateTime? value) {
            if (value != null &&
                (widget.op.start.isAfter(value) || widget.op.end.isBefore(value))) {
              return "Ticket falls outside of operation range";
            }
            return null;
          },
          onDateSelected: (DateTime value) {
            _date = value;
          },
        ));
    
    opened by jclement 2
  • feat(date_form_field): add a selectedDate

    feat(date_form_field): add a selectedDate

    I add a selectedDate attribute on the DateTimeFormField class. In one project I must change the displayed value when a variable change, maybe this can be useful to other people

    opened by Pierre-Monier 2
  • use24hFormat doesn't work with Material on DateTimeFormField

    use24hFormat doesn't work with Material on DateTimeFormField

    If you construct a DateTimeFormField like so:

    DateTimeFormField(
          mode: DateTimeFieldPickerMode.dateAndTime,,
          dateFormat: DateFormat.yMd().add_jm(),
          use24hFormat: false,
          ...
        )
    

    when the time picker is displayed, it is in 24h format, not 12h format as specified.

    I'm using the Material widgets with date_field 3.0.0. It appears that the showMaterialTimePicker() function does not call showTimePicker() (https://api.flutter.dev/flutter/material/showTimePicker.html) in a 12h/24h method as described in the doc.

    opened by dsyrstad 2
  • Selection in 24h mode

    Selection in 24h mode

    Hi, not sure if #13 was actually referencing the same issue but I suppose it didn't.

    I would need the date and time selection to be in 24h format. Which means the AM/PM could be removed... image

    Is this possible? I couldn't find any way to make this possible. Could this be added?

    opened by WieFel 2
  • Change calendar and timer default color

    Change calendar and timer default color

    Hello! Is it possible when you press the field and the calendar pops up to change the default color of the calendar? Currently it is blue. The same goes for time selection. Thank you

    opened by gdet 1
  • Allow caller to pick default entry mode

    Allow caller to pick default entry mode

    Hello! This PR adds the ability to pick the initial state (touch or keyboard) of the time picker widget. We needed this for a better web experience. It might be worth to have the switching logic in this package, but for now it's nice to have the option to pick the initial state.

    Thank you!

    opened by blopker 0
  • Not using all the theme's style settings

    Not using all the theme's style settings

    I would like to use the DateTimeFormField within a larger form, together with other form fields. Obviously that is not a problem, but where all the form field automatically use all of the theme's style settings, the DateTimeFormField does not. It has noticeably smaller height and once a date is selected it will expand to accomodate the label and value together. All other fields have the necessary height to accomodate it all without resizing. But even then, after the resize, it is still smaller than the other form fields.

    I have not set any specific styling to either of the elements, so all should be the same based on the theme's style settings. Which theme style settings should I change to make the DateTimeFormField also use the standard? Or, can the widget be updated so that it will use the theme?

    opened by ehusmann 1
Owner
Gaspard Merten
CTO @ GiveActions - Flutter, Angular Dart, ... enthusiast (yep the whole dart ecosystem 😄) - Student at the Polytechnic School of Brussels - and more... 👍
Gaspard Merten
Flutter ShopApp, you can see products and their prices, categories and their products, search for a product, add to favorite, add to cart, sign in and sign up.

shop_app_2 A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Muhammed Rezk Rajab 10 Aug 7, 2022
A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Android, Web, Windows, Linux and macOS.

cross_connectivity A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Androi

MarchDev Toolkit 29 Nov 15, 2022
Developed a Group chat application using Flutter and Firebase, where users can register and create groups or join already existing groups and start conversing with each other.

GroupChatApp About Developed a Group chat application using Flutter and Firebase, where users can register and create groups or join already existing

Ahmed Gulab Khan 221 Dec 1, 2022
E-Studying-V1 - Flutter application where you can download files from an api and unarchive them and open them and see their contents

E-Studying-V1 - Flutter application where you can download files from an api and unarchive them and open them and see their contents

Chakib Ammar Aouchiche 0 Jan 20, 2022
A mobile image uploader in which you can upload image to your personal gallery from either your camera or mobile gallery and it can detect your current geographic location and address using firebase firestore and storage.

Image Uploader In Flutter About It is an Image Uploader gallery which tracks your address from which you're uploading using Flutter and Image picker.

Prahen parija 6 Dec 20, 2022
null 357 Dec 27, 2022
This is a shop-app you can see the products and With prices and knowing if there are discounts and adding your favorite products to the favorite products page

This is a shop-app you can see the products and With prices and knowing if there are discounts and adding your favorite products to the favorite products page, you can search for a specific product and also modify personal information from the settings , I made it using REST APIs by using (Dio packedge) , (shared Preference) and state management (Bloc/cubit

null 2 Oct 27, 2022
A weather application that show the current weather for your location and forecast for 6 days, and favorite city and other locations

Weather Application App concept created with Flutter using Dart programming language ad it's a demanded task in my internship at Algoriza About An app

Mohamed Mohamedy 4 Nov 13, 2022
Utility Manager Flutter Application is made with Flutter and Supabase which allows user to add task, set remainder to the task, set color to separate tasks and it allows to add URL with URL's informations.

Utility Manager Flutter Application! Utility Manager Flutter Application is made with Flutter and Supabase which allows user to add task, set remainde

Kathirvel Chandrasekaran 6 Jan 6, 2022
Expenses tracker built with Flutter and Dart making use of Provider, Intl, Syncfusion Flutter Datepicker and more

expense_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

Atuoha Anthony 2 Dec 10, 2022
News App created in Flutter using News API for fetching realtime data and Firebase as the backend and authenticator.

News Buzz News App created in Flutter using News API for fetching realtime data and Firebase as the backend and authenticator. Features Custom news fe

Ankur Kedia 545 Dec 30, 2022
A Simple Todo app design in Flutter to keep track of your task on daily basis. Its build on BLoC Pattern. You can add a project, labels, and due-date to your task also you can sort your task on the basis of project, label, and dates

WhatTodo Life can feel overwhelming. But it doesn’t have to. A Simple To-do app design in flutter to keep track of your task on daily basis. You can a

Burhanuddin Rashid 1k Jan 6, 2023
gui automation based on pyautogui python as backend and flutter desktop as frontend, drag and drop tool, no coding required.

GUI_AUTOMATION gui automation based on pyautogui python as backend and flutter desktop as frontend, drag and drop tool, no coding required. Install py

Hassan Kanso 34 Oct 30, 2022
GetDoctor is a complete app developed in Flutter, Firebase and Blazor,.Net Core API and SQL Server

GetDoctor ?? ?? ?? GetDoctor is a complete app developed in Flutter, Firebase and Blazor,DotNet Core API and SQL Server GetDoctor is a complete packag

Sunil Vijayan 69 Dec 19, 2022
An android app built using flutter that displays and forecast the specific city Weather and Climate for dynamic time event by collecting the data from API that is provided for free by OPENWEATHER site.

clima_weather_reporter A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get y

dev_allauddin 3 Feb 3, 2022
Starter architectures for your next Flutter project in order to make it scalable and easy for maintenance and tests.

?? ?? ?? Flutter Starter Architecture (MVVM) My custom starter project for Flutter apps. I was looking for a simple way to build Flutter app in a scal

Junior Medehou 29 Dec 25, 2022
A Flutter application for Muslims that help them challenge and motivate themselves and their friends to read Azkar in a fun way.

A Flutter application for Muslims that help them challenge and motivate themselves and their friends to read Azkar in a fun way.

null 33 Oct 30, 2022
About This is Personal Expenses Planner. You can add your expenses in to the app and manage your transaction. and you can see How much did you spend on which day. I developed this project using flutter.

expense_planner A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Darshit Rudani 5 Jul 6, 2022