skip to Main Content

How do I set auto select the date of birth textfield based on the ID number. Example ID 901201 so for date of birth textfield will show 01-12-1990. When you enter the ID number, the date of birth textfield will automatically select the date based on the ID number. I don’t know how to make it. I’ve never done this before and I’m new in flutter. Can anyone help me?

if (_idNumber.text.isEmpty) {
        createToast(_fToast, false, "ID number is empty");
        return;
      } else {
        var year = 0;
        var id= _icNumber.text;
        var x = int.parse(id.substring(0, 2));
        var month = id.substring(2, 4);
        var day = id.substring(4, 6);
        if (x < 10) {
          year = x + 2000;
        } else {
          year = x + 1900;
        }
        var dob = DateTime(year, int.parse(month), int.parse(day));
        final yr = DateTime.now().year - dob.year;
        if ((yr - 1) < 18) {
          );
          return;
        }
      }


Widget dateOfBirth(  
  ) =>
      Row(
        children: [
          SizedBox(
            width: 60,
            child: TextFormField(
               inputFormatters: <TextInputFormatter>[
                FilteringTextInputFormatter.digitsOnly,
                LengthLimitingTextInputFormatter(2),
              ],
             onChanged: (value) {
                _dobDay.text = value;
              },
              onSaved: (value) {
                _dobDay.text = value!;
              },
              maxLines: 1,
              style: const TextStyle(
                  color: Color(0xFF0D212D), height: 1.4, fontSize: 15),
              decoration: const InputDecoration(
                hintText: "DD",
                isDense: true,
                contentPadding: EdgeInsets.all(13.5),
                border: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.black12)),
                enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: Colors.black12)),
                focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: Colors.black12)),
              ),
            ),
          ),
          const Text(" / "),
          SizedBox(
            width: 60,
            child: TextFormField(
              inputFormatters: <TextInputFormatter>[
                FilteringTextInputFormatter.digitsOnly,
                LengthLimitingTextInputFormatter(2),
              ],
              onChanged: (value) {
                _dobMonth.text = value;
              },
              onSaved: (value) {
                _dobMonth.text = value!;
              },
              maxLines: 1,
              style: const TextStyle(
                  color: Color(0xFF0D212D), height: 1.4, fontSize: 15),
              decoration: const InputDecoration(
                hintText: "MM",
                isDense: true,
                contentPadding: EdgeInsets.all(13.5),
                border: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.black12)),
                enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: Colors.black12)),
                focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: Colors.black12)),
              ),
            ),
          ),
          const Text(" / "),
          SizedBox(
            width: 100,
            child: TextFormField(
              inputFormatters: <TextInputFormatter>[
                FilteringTextInputFormatter.digitsOnly,
                LengthLimitingTextInputFormatter(4),
              ],
              onChanged: (value) {
                _dobYear.text = value;
              },
              onSaved: (value) {
                _dobYear.text = value!;
              },
              maxLines: 1,
              style: const TextStyle(
                  color: Color(0xFF0D212D), height: 1.4, fontSize: 15),
              decoration: const InputDecoration(
                hintText: "YYYY",
                isDense: true,
                contentPadding: EdgeInsets.all(13.5),
                border: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.black12)),
                enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: Colors.black12)),
                focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: Colors.black12)),
              ),
            ),
          ),
        ],
      );

2

Answers


  1. have you tried

    select "add in your set link" ID "code of ID"?

    I don’t know the exact way you’ve done this but….it should be pretty simple if you’ve done it right.

    you should be able to just do your select function you made ,and the ID number and submit the code prompt.

    it should work , and be fluid And simple.

    if it isn’t doing that, you need to go back in and fiddle with your work until this happens because you probably have a mistake somewhere in your formulas.

    Login or Signup to reply.
  2. Then you have to define TextEditingController for TextFormField and have to assign it.

    TextFormField Controller

    And when you’re parsing Day,Month and Year from ID, you have to pass that value to particular textEditingController.

    Like doDayController.text=day;
    And so on for month and year.
    So that value directly added to their respective textformfield.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search