7.1 C
London
Tuesday, October 31, 2023

android – Flutter: Validate TextFormField not working in my case


I’ve 2 TextFormField, in first TextFormField, get information from bottomsheet and assign this information to controller, in second TextFormField, only a regular textual content subject to enter a textual content. Code like this:

TextFormField(
                      onTap: () {
                        // That is bottomsheet
                        showBottomsheet(
                          context,
                          filterOptions:
                              context.learn<EOfficeBloc>().registerMeetingOption,
                        );
                         context.learn<EOfficeBloc>()
                              .applyFilterRegisterMeeting(
                                  filterOption: filterOption);
                      },
                      readOnly: true,
                      controller:
                          context.learn<EOfficeBloc>().meetingRoomController,
                      validate: (worth) {
                        if (meetingRoom?.isEmpty ?? false) {
                          return 'Validate';
                        }
                        return null;
                      },
),
TextFormField(
                      validate: (worth) {
                        if (worth?.isEmpty ?? true) {
                          return 'Validate';
                        }
                        return null;
                      },
                      onChange: (worth) {
                        if (worth.isNotEmpty) {
                          int amount = int.parse(worth);
                          remaining filterOption = context
                              .learn<EOfficeBloc>()
                              .registerMeetingOption
                              .copyWith(peopleNumber: amount);
                          context
                              .learn<EOfficeBloc>()
                              .applyFilterRegisterMeeting(
                                  filterOption: filterOption);
                        }
                      },
                      controller:
                          context.learn<EOfficeBloc>().peopleNumberController,
)

In school bloc:

  TextEditingController? meetingRoomController;
  TextEditingController? peopleNumberController;

  void applyFilterRegisterMeeting({
    required RegisterInformationMeetingFilterOption filterOption,
  }) {
    _registerMeetingOption = filterOption.copyWith();
    if (filterOption.meetingRoomList.isNotEmpty) {
      meetingRoomController =
          TextEditingController(textual content: filterOption.meetingRoomList.first.title);
    }
    if (filterOption.peopleNumber != null) {
      peopleNumberController =
          TextEditingController(textual content: filterOption.peopleNumber.toString());
    }
}

The difficulty is: when i select information in bottomsheet and apply, meetingRoomController had information with subject ‘title’ however worth in validate is empty so it not conceal a textual content ‘Validate’. After which when i click on in second TextFormField and sort a textual content, worth in validate of first TextFormField solely conceal ‘Validate’. I dont know cause why not conceal ‘Validate’ when i select an information in bottomsheet?
Im very dangerous in english, so assist me pls. Thank u very a lot!

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here