Skip to content

DatePicker - if only year picked reset to initial date #75693

Closed

Description

@marinat

Steps to Reproduce

Open DatePicker in application for example like this:

    var now = DateTime.now();
    var selectedDate = DateTime(now.year - 3);
    if (_birthDateController.text.isNotEmpty)
      selectedDate = dateFormat.parse(_birthDateController.text);
    final DateTime picked = await showDatePicker(
        context: context,
        initialDatePickerMode: DatePickerMode.year,
        initialDate: selectedDate,
        firstDate: DateTime(now.year - 100),
        locale: Localizations.localeOf(context),
        lastDate: now);

And select 2009 year. Do not pick day. Click ok button in picker dialog.

Expected results:
Picker date result == 01.01.2009

Actual results:
Picker date result == initialDate

Activity

  1. pedromassangocode commented on Feb 9, 2021

    @pedromassangocode

    Hi @marinat
    Can you please provide your flutter doctor -v and a minimal complete reproducible code sample?
    Thank you

  2. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 9, 2021
  3. marinat commented on Feb 9, 2021

    @marinat
    Author
    flutter doctor -v
    [✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-x64, locale ru-RU)
        • Flutter version 1.22.6 at /Users/rinat/Work/flutter
        • Framework revision 9b2d32b605 (3 weeks ago), 2021-01-22 14:36:39 -0800
        • Engine revision 2f0af37152
        • Dart version 2.10.5
    
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/rinat/Library/Android/sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.3, Build version 12C33
        • CocoaPods version 1.10.0
    
    [!] Android Studio (version 4.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    
  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 9, 2021
  5. pedromassangocode commented on Feb 9, 2021

    @pedromassangocode

    Hi @marinat
    Can you please provide your flutter doctor -v and a minimal complete reproducible code sample?
    Thank you

    I need a minimal code sample that reproduces the issue as well.

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 9, 2021
  7. marinat commented on Feb 9, 2021

    @marinat
    Author
    code sample
    import 'dart:async';
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      DateTime currentDate;
    
      Future<void> _selectDate(BuildContext context) async {
        final DateTime pickedDate = await showDatePicker(
            context: context,
            initialDate: DateTime.now(),
            initialDatePickerMode: DatePickerMode.year,
            firstDate: DateTime(2015),
            lastDate: DateTime(2050));
        if (pickedDate != null && pickedDate != currentDate)
          setState(() {
            currentDate = pickedDate;
          });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text("DatePicker"),
          ),
          body: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Text(currentDate != null ? currentDate.toString() : 'No date'),
                RaisedButton(
                  onPressed: () => _selectDate(context),
                  child: Text('Select date'),
                ),
              ],
            ),
          ),
        );
      }
    }
  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 9, 2021
  9. marinat commented on Feb 9, 2021

    @marinat
    Author

    I think that's not a really bug, but it's confusing users who has for example birthday at first day of month.

  10. pedromassangocode commented on Feb 10, 2021

    @pedromassangocode

    Hi @marinat
    I think this is not a bug as well. This dialog is expected to be used to select both, the year and day. If you only select the year the selected date is not complete.

    but it's confusing users who has for example birthday at first day of month

    I'm not sure what is confusing here, if birthday is at first day of month user just need to select the month and then the first day of that month.

  11. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 10, 2021
  12. added
    r: invalidIssue is closed as not valid
    and removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 10, 2021
  13. github-actions commented on Aug 6, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in triagePresently being triaged by the triage teamr: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions