dylanwuzh / flutter-cupertino-date-picker

Flutter cupertino style date picker.
Apache License 2.0
362 stars 417 forks source link

NoSuchMethodError was thrown building DatePickerWidget(dirty, state: _DatePickerWidgetState#3ec38): #102

Closed JSBmanD closed 4 years ago

JSBmanD commented 4 years ago

By some strange circumstances your code in examples not working in my project.

[✓] Flutter (Channel stable, v1.17.1, on Mac OS X 10.14.6 18G103, locale en-RU)

Future<void> _selectDate(BuildContext context) async {
    DatePicker.showDatePicker(
      context,
      locale: DateTimePickerLocale.en_us,
      initialDateTime: DateTime.now(),
      dateFormat: 'dd-mm-yyyy',
      onMonthChangeStartWithFirstDate: true,
      pickerTheme: DateTimePickerTheme(
        showTitle: true,
        confirm: Text('Done', style: TextStyle(color: Colors.black)),
      ),
      minDateTime: DateTime.parse(MIN_DATETIME),
      maxDateTime: DateTime.parse(MAX_DATETIME),
      onConfirm: (dateTime, List<int> index) {
        if (mounted)
          setState(() {
            selectedDate = dateTime;
            widget.controller.text = formatter.format(selectedDate);
          });
      },
    );
  }
flutter: 2010, 2021

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building DatePickerWidget(dirty, state: _DatePickerWidgetState#3ec38):
The getter 'last' was called on null.
Receiver: null
Tried calling: last

The relevant error-causing widget was: 
  MaterialApp file:///Users/sss/Documents/Projects/sss/lib/main.dart:43:12
When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      _DatePickerWidgetState._renderDatePickerColumnComponent (package:flutter_cupertino_date_picker/src/widget/date_picker_widget.dart:220:34)
#2      _DatePickerWidgetState._renderDatePickerWidget.<anonymous closure> (package:flutter_cupertino_date_picker/src/widget/date_picker_widget.dart:183:29)
#3      List.forEach (dart:core-patch/growable_array.dart:282:8)
#4      _DatePickerWidgetState._renderDatePickerWidget (package:flutter_cupertino_date_picker/src/widget/date_picker_widget.dart:180:15)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
JSBmanD commented 4 years ago

I found out that it was legacy format, changing to 'yyyy-MMMM-dd' helped.