Skip to content

Able to select dates that are before the given "firstDate" within the Date Picker #6501

@darthvadrismydad

Description

@darthvadrismydad

Steps to Reproduce

  1. Run the sample code in an Android VM
  2. Click the "Pick Date" button
  3. Select a date that is before the date the test is being run (e.g. if it is October 24th, 2016, pick the 23rd)
  4. App should enter an error state

Sample Code:

import 'package:flutter/material.dart';

void main() {
  runApp(
    new MaterialApp(
      title: 'Date Picker Bug',
      theme: new ThemeData(
        primarySwatch: Colors.red,
      ),
      home: new DatePickerBug(),
    ),
  );
}

class DatePickerBug extends StatefulWidget {
  DatePickerBug({Key key}) : super(key: key);

  @override
  _DatePickerBugState createState() => new _DatePickerBugState();
}

class _DatePickerBugState extends State<DatePickerBug> {

  @override
  Widget build(BuildContext context) {

    return new Scaffold(
      body: new RaisedButton(
        child: new Text("Pick Date"),
        onPressed: _handleDateSelection
      )
    );
  }

  _handleDateSelection() async {
    var now = new DateTime.now();
    await showDatePicker(
      context: context,
      initialDate: now,
      firstDate: now,
      lastDate: now.add(new Duration(days: 2))
    );
  }
}

Error Message:

I/flutter : ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter : The following assertion was thrown building _DatePickerDialog(dirty; state:
I/flutter : _DatePickerDialogState(511556607)):
I/flutter : 'package:flutter/src/material/date_picker.dart': Failed assertion: line 306 pos 12:
I/flutter : 'selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)' is not true.
I/flutter : 
I/flutter : When the exception was thrown, this was the stack:
I/flutter : #2      MonthPicker.MonthPicker (package:flutter/src/material/date_picker.dart:306:12)
I/flutter : #3      _DatePickerDialogState._buildPicker (package:flutter/src/material/date_picker.dart:577:20)
I/flutter : #4      _DatePickerDialogState.build (package:flutter/src/material/date_picker.dart:602:16)
I/flutter : #5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:2766:23)
I/flutter : #6      BuildableElement.rebuild (package:flutter/src/widgets/framework.dart:2667:5)
I/flutter : #7      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:1689:33)
I/flutter : #8      BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding&WidgetsBinding.beginFrame (package:flutter/src/widgets/binding.dart:297:20)
I/flutter : #9      BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:162:5)
I/flutter : #10     BindingBase&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:648:15)
I/flutter : #11     BindingBase&SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:583:9)
I/flutter : #12     _beginFrame (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:69)
I/flutter : (elided 2 frames from class _AssertionError)
I/flutter : ════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter Analyze Result:

Running 'pub get' in test-app...                     0.5s
Analyzing lib/main.dart...

Flutter Doctor

[✓] Flutter (on Linux, channel master)
    • Flutter at /usr/local/flutter
    • Framework revision 48690d7c2e (7 days ago), 2016-10-17 12:50:47
    • Engine revision d999f6c123
    • Tools Dart version 1.20.1

[✓] Android toolchain - develop for Android devices (Android SDK 24.0.2)
    • Android SDK at /usr/local/android/Sdk
    • Platform android-24, build-tools 24.0.2
    • OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)

[✓] Atom - a lightweight development environment for Flutter
    • flutter plugin version 0.2.6
    • dartlang plugin version 0.6.42

[✓] Connected devices
    • Android SDK built for x86 • emulator-5554 • android-x86 (emulator)

I would think that either the action is permitted and will not error out (remove the assertion), or this behavior should not be possible (gray out the unavailable dates?).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions