A Flutter package for adding a DateRange widget into a form. A date picker UX is provided by showDateRangePicker.

Overview

date_range_form_field

A Flutter package for adding a DateRange widget into a form. A date picker UX is provided by showDateRangePicker. The widget will accept InputDecoration or use the default from the app's theme. Additionally, the widget will accept a date format, defaulting to MM-dd-yyyy.

Usage

This widget should be used like any other FormField within a form. It is important to note that the firstDate and lastDate properties correspond to the first and last valid dates. This widget must have a MaterialWidget ancestor, such as a MaterialApp

Example

import 'package:date_range_form_field/date_range_form_field.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: MyFormField(),
    );
  }
}

class MyFormField extends StatefulWidget {
  @override
  _MyFormFieldState createState() => _MyFormFieldState();
}

GlobalKey<FormState> myFormKey = new GlobalKey();

class _MyFormFieldState extends State<MyFormField> {
  DateTimeRange? myDateRange;

  void _submitForm() {
    final FormState? form = myFormKey.currentState;
    form!.save();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Date Range Form Example"),
      ),
      body: SafeArea(
        child: Form(
          key: myFormKey,
          child: Column(
            children: [
              SafeArea(
                child: DateRangeField(
                    enabled: true,
                    initialValue: DateTimeRange(
                        start: DateTime.now(),
                        end: DateTime.now().add(Duration(days: 5))),
                    decoration: InputDecoration(
                      labelText: 'Date Range',
                      prefixIcon: Icon(Icons.date_range),
                      hintText: 'Please select a start and end date',
                      border: OutlineInputBorder(),
                    ),
                    validator: (value) {
                      if (value!.start.isBefore(DateTime.now())) {
                        return 'Please enter a later start date';
                      }
                      return null;
                    },
                    onSaved: (value) {
                      setState(() {
                        myDateRange = value!;
                      });
                    }),
              ),
              ElevatedButton(
                child: Text('Submit'),
                onPressed: _submitForm,
              ),
              if (myDateRange != null)
                Text("Saved value is: ${myDateRange.toString()}")
            ],
          ),
        ),
      ),
    );
  }
}

Contributing

Contributions are welcome as pull requests to the github repo. Please open issues on the repo for feature requests or bug reports.

Comments
  • Can't choose later dates

    Can't choose later dates

    I was excited find such a neat package until I realized it can't be used for my project because, i can't select dates before the current one. At the very least it should be scrollable and go as far back as 1990s.

    opened by Nana-Kwame-bot 1
  • Bug/not able to display hinttext

    Bug/not able to display hinttext

    Fixed display of hintText and added support for the fieldStartHintText and fieldEndHintText parameters in the showDateRangePicker function. This is fixing the issues discussed in: #6 #7

    opened by Cali0707 1
  • Label and Hint problem on input

    Label and Hint problem on input

    In your code there is this : This is causing a problem when you want to override the text, because there is an error in the attribute name.

    fieldStartHintText: fieldStartLabelText ?? 'Start Date',
    fieldEndLabelText: fieldEndLabelText ?? 'End Date') ?? state.value;
    

    I think that you should set something like :

    fieldStartHintText: fieldStartHintText ?? 'Hint Start Date',
    fieldStartLabelText: fieldStartLabelText ?? 'Label Start Date',
    fieldEndHintText: fieldEndHintText ?? 'Hint End Date',
    fieldEndLabelText: fieldEndLabelText ?? 'Label End Date',
    
    bug 
    opened by Whisper40 1
  • DateRangeField does not allow me to select older dates

    DateRangeField does not allow me to select older dates

    I'm currently working on a project where I need to select older dates for getting some history data. but unfortunately this plugin doesn't allow me to do that.

    opened by ambanikousik 1
  • Type 'DateTimeRange' not found

    Type 'DateTimeRange' not found

    And I got an error

    ../../flutter/.pub-cache/hosted/pub.dartlang.org/date_range_form_field-0.0.4/lib/date_range_form_field.dart:184:9: Error: Type 'DateTimeRange' not found. final DateTimeRange initialValue;

    Running on sdk 1.17.5

    opened by YoboZorle 1
  • Not able to display hintText

    Not able to display hintText

    In your example code you are using hintText and labelText. LabelText is working, but hintText is just not displaying.

    When we use hintText, it should display the sentence, and once we click it should be displayed as a labelText. In your case, it is not doing this default beaviour.

    You can try on your side, but i think that there is a problem with the hintText (while not using initialValue.. ) .

    bug 
    opened by Whisper40 0
  • InitialValue and pass key to super

    InitialValue and pass key to super

    I've been using this excellent package for awhile, with changes 1 and 2 in production for years with no issues. I figured it's time to commit these changes back to this repo if you'll have them:

    1. The initialValue wasn't being set correctly, so I've added a few lines to set it in the state.
    2. Change default lastDate to be simply 5 days later, rather than 5 years later.
    3. Pass along key to super. I needed this to programmatically clear the date.
    opened by percula 0
  • Issue with the date range picker format

    Issue with the date range picker format

    Hello Dev team. I would like to commend you on the effort you put into the creation of the package.

    There's an issue in the package, however, where the date format is a bit weird in the date-range field. It gives me a04/38/2022 as a date format. This is the sample: Simulator Screen Shot - iPhone Xʀ - 2022-04-25 at 14 57 31

    I tried editing the package to solve this problem but it still persists. Please try fixing the issue.

    opened by georonathan47 0
  • Not able to translate

    Not able to translate "Date Range" on input side

    I don't see in your code or flutter code something for translating this "Date Range". I already searched in their repo for this string, but cannot find it...

    opened by Whisper40 0
  • Not able to translate Start Date - End Date on Calendar mode

    Not able to translate Start Date - End Date on Calendar mode

    I don't find in your code something for changing this, it is related to you or flutter ?

    I set this in the code :

    helpText: 'Sélectionnez un interval de dates',
    fieldStartLabelText: 'Date de début',
    fieldEndLabelText: 'Date de fin',
    fieldStartHintText: 'Début',
    fieldEndHintText: 'Fin',
    

    (this code works for translating on the input side as requested in another issue) image

    Version : 1.0.2 (latest)

    opened by Whisper40 0
  • Validation problem date format on input (not calendar)

    Validation problem date format on input (not calendar)

    I definied dateFormat: DateFormat('dd/MM/yyyy'), When i select dates in the calendar, the validation is working, and the display is OK.

    But if tape the date in the input, i cannot validate it with the format provided above. The validator want's a 'MM/dd/yyyy'

    opened by Whisper40 3
Releases(1.0.2)
Owner
JMA Consulting
JMA Consulting
A pure dart package with collection of Nepali Utilities like Date converter, Date formatter, DateTime, Nepali Numbers, Nepali Unicode, Nepali Moments and many more.

Nepali Utilities for Dart A pure dart package with collection of Nepali Utilities like Date converter, Date formatter, DateTime, Nepali Number, Nepali

Sarbagya Dhaubanjar 23 Nov 22, 2022
Allows to use date pickers without dialog. Provides some customizable styles for date pickers.

flutter_date_pickers Allows to use date pickers without dialog. Provides some customizable styles for date pickers. A set of date pickers: DayPicker f

null 196 Dec 29, 2022
Flutter Date Picker Library that provides a calendar as a horizontal timeline.

DatePickerTimeline Flutter Date Picker Library that provides a calendar as a horizontal timeline. How To Use Import the following package in your dart

LiLi 0 Oct 25, 2021
Flutter Cupertino Date Picker

Flutter Cupertino Date Picker [pub packages] | 中文说明 Flutter cupertino date picker. Usage 1. Depend Add this to you package's pubspec.yaml file: depend

Ryuuzaki 0 Nov 9, 2021
Flutter Date Picker Library that provides a calendar as a horizontal timeline

Flutter Date Picker Library that provides a calendar as a horizontal timeline.

Vivek Kaushik 214 Jan 7, 2023
A flutter date time picker

Flutter Datetime Picker (Pub) flutter_datetime_picker A flutter date time picker inspired by flutter-cupertino-date-picker you can choose date / time

Realank 559 Dec 26, 2022
Beautiful Date Range Picker Dialog For Flutter

Beautiful Date Range Picker Dialog For Flutter

Mazouzi Aymene 36 Dec 22, 2022
Flutter Date & Time Range Picker

F-DateTimeRangePicker Date and Time Range Picker for Flutter Installing: dependencies: f_datetimerangepicker: ^0.2.0 Using: import 'package:f_datet

Long Phan 20 Jan 18, 2022
A DateTime picker that lets user to select a date and the time, with start & end as a range

Omni DateTime Picker A DateTime picker that lets user to select a date and the time, with start & end as a range. Screenshots Getting started Add this

null 17 Dec 29, 2022
A persian (farsi,shamsi) datetime picker for flutter, inspired by material datetime picker.

?? A persian (farsi,shamsi) datetime picker for flutter, inspired by material datetime picker. Persian datetime picker inspired by material datetime p

Persian Flutter Community 142 Dec 19, 2022
Flutter package to create a day date scroller

scrolling_day_calendar A flutter calendar package to allow users to scroll through given dates either by swiping left and right or pressing the arrows

null 8 Jul 12, 2020
Calendar widget for flutter that is swipeable horizontally. This widget can help you build your own calendar widget highly customizable.

flutter_calendar_carousel Calendar widget for flutter that is swipeable horizontally. This widget can help you build your own calendar widget highly c

dooboolab 750 Jan 7, 2023
A day night time picker for Flutter. Beautiful day and night animation with Sun and Moon assets.

DayNightTimePicker A day night time picker for Flutter with Zero Dependencies. Default style: IOS style: View it on pub.dev Installation Add to pubspe

Subhamay Dutta 68 Dec 29, 2022
CalendarDatePicker2 - A lightweight and customizable calendar picker based on Flutter CalendarDatePicker

A lightweight and customizable calendar picker based on Flutter CalendarDatePicker, with support for single date picker, range picker and multi picker.

Neo Liu 27 Dec 22, 2022
Calendar widget for flutter

Calendar Shows a scrolling calendar list of events. This is still relatively basic, it always assumes that the getEvents returns the entire list of ca

null 223 Dec 19, 2022
Highly customizable, feature-packed calendar widget for Flutter

Table Calendar Highly customizable, feature-packed Flutter Calendar with gestures, animations and multiple formats. Table Calendar with custom styles

Aleksander Woźniak 1.5k Jan 7, 2023
Calendar widget library for Flutter apps.

Calendarro Calendar widget library for Flutter apps. Offers multiple ways to customize the widget. Getting Started Installation Add dependency to your

Adam Styrc 97 Nov 30, 2022
A calendar widget for Flutter.

flutter_calendar A calendar widget for Flutter Apps. Borrowed DateTime utility functions from the Tzolkin Calendar web element. Usage Add to your pubs

AppTree Software, Inc 336 Sep 6, 2022
A calendar widget to easily scroll through the years 🗓

Flutter Scrolling Calendar A customizable calendar widget to easily scroll through the years. Features Choose range of years and the initial year to s

Menno Renkens 113 Nov 19, 2022