Cupertino Date Picker Flutter NoSuchMethod error (datePickerHour()) in implementation

257

add this

MaterialApp(
  localizationsDelegates: [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate
  ],
  supportedLocales: [
    const Locale('ru', "RU"),
    const Locale('en', "US"),
  ],
Share:
257
albertojaredsd
Author by

albertojaredsd

Updated on December 26, 2022

Comments

  • albertojaredsd
    albertojaredsd over 1 year

    Im new in Flutter and Im having troubles implementing a Date Picker Widget, that I have already tested apart, in my App. It just throws an error NoSuchMethodError-> The method 'datePickerHour' was called on null. Receiver: null Tried calling: datePickerHour(0)

    Ive included the right cupertino package and Ive done the implementation exactly as in my previous testing code. I just dont get why is this method (datePickerHour()) inside CupertinoDatePicker not being recognized. Could somebody help me spotting the error? Thank you in advance.

    Code is:

                                      FlatButton(
                                          onPressed: () {                                             
                                              showModalBottomSheet(
                                                  context: context,
                                                  builder:
                                                      (BuildContext builder) {
                                                    return Container(
                                                      height:
                                                          MediaQuery.of(context)
                                                                  .copyWith()
                                                                  .size
                                                                  .height /
                                                              3,
                                                      color: Colors.white,
                                                      child:
                                                          CupertinoDatePicker(
                                                        mode:
                                                            CupertinoDatePickerMode
                                                                .dateAndTime,
                                                        onDateTimeChanged:
                                                            (picked) {
                                                          if (picked != null &&
                                                              picked !=
                                                                  selectedDate)
                                                            setState(() {
                                                              selectedDate =
                                                                  picked;
                                                            });
                                                        },
                                             
                                                        initialDateTime: selectedDate,
                                                        minimumYear: 2020,
                                                        maximumYear: 2025,
                                                      ),
                                                    );
                                                  });
                                            }
                                          },
                                          padding: EdgeInsets.symmetric(
                                              vertical: 14),
                                          color: Theme.of(context).accentColor,
                                          shape: StadiumBorder(),
                                          child: Icon(
                                            Icons.calendar_today,
                                            color:
                                                Theme.of(context).primaryColor,
                                          )),