mytooyo / board_datetime_picker

Picker to select date and time for Flutter. It is both a calendar and a picker, offering a variety of options as a package.
BSD 3-Clause "New" or "Revised" License
7 stars 6 forks source link

controller.setText problem #36

Closed matteoberla closed 6 days ago

matteoberla commented 2 weeks ago

Hi, can you please try this code and see what's wrong?

-at the beginning the textcontroller shows '01/06/2024' -> it works -if i delete it should be supposed to set the text to '03/06/2024' -> it works -if i delete again the text the controller should set again the text but nothing happens -> Problem! the text field stays blank.

I think that it used to work some version ago as some parts of my code now have the same problem.

//before the build
BoardDateTimeTextController controller = BoardDateTimeTextController();
  String? date = "2024-06-01";

//widget
BoardDateTimeInputField(
            controller: controller,
            pickerType: DateTimePickerType.date,
            onFocusChange: (hasFocus, selectedDate, input) {
              if (!hasFocus) {
                print("---$selectedDate---$input---");
                if (selectedDate != null && input != "") {
                  controller.setText("06/06/2024");
                } else {
                  print("set text");
                  //reimposto data originale
                  controller.setText("03/06/2024");
                }
              }
            },
            initialDate: DateTime.tryParse(date ?? ""),
            showPicker: false,
            onChanged: (DateTime date) {},
            options: const BoardDateTimeOptions(
              languages: BoardPickerLanguages.it(),
              startDayOfWeek: DateTime.monday,
              pickerFormat: PickerFormat.dmy,
              textColor: darkTextColor,
              activeColor: mainColor,
              activeTextColor: lightTextColor,
              showDateButton: false,
              pickerSubTitles: BoardDateTimeItemTitles(
                  year: "Anno",
                  month: "Mese",
                  day: "Giorno",
                  hour: "Ora",
                  minute: "Minuto"),
            ),
          ),
matteoberla commented 1 week ago

Here is a video of the problem with different datepicker types, Here i'm on web, and just the time type works fine. datetime works first time but then adds '/00/00' date works first time but then just stays empty

https://github.com/mytooyo/board_datetime_picker/assets/69200334/03c16b7e-e7d4-4ef0-a0f0-37dd2b6b6601

mytooyo commented 6 days ago

@matteoberla Thank you for your report and research. I have identified the cause and corrected it.

matteoberla commented 6 days ago

Thank you very much for your help, now it works perfectly.