'TextFormField update input to 1 if user keys in 0 flutter

I am having a TextFormField as a child in Form like below


                                                  Form(
                                                        autovalidateMode:
                                                            AutovalidateMode
                                                                .onUserInteraction,
                                                        child: TextFormField(
                                                          maxLength:
                                                              maxInputLength,
                                                          controller:
                                                              quantityController,
                                                          cursorHeight: 20,
                                                          textAlign:
                                                              TextAlign.center,
                                                          decoration: InputDecoration(
                                                              counterText: "",
                                                              contentPadding:
                                                                  const EdgeInsets
                                                                          .only(
                                                                      left: 1,
                                                                      right: 1,
                                                                      top: 10,
                                                                      bottom:
                                                                          10),
                                                              border: OutlineInputBorder(
                                                                  borderRadius:
                                                                      BorderRadius
                                                                          .circular(
                                                                              20)),
                                                              isDense: true),
                                                          onChanged: (q) {

                                                          },
                                                          validator: (quantity){

                                                          },
                                                          keyboardType:
                                                              TextInputType
                                                                  .number,
                                                          inputFormatters: <
                                                              TextInputFormatter>[
                                                            FilteringTextInputFormatter
                                                                .digitsOnly
                                                          ],
                                                        ))

What i would like to achieve is when i type a value like 0 the TextFormField automatically replaces the 0 with 1. I have tried using a TextEditingController but its showing a square box momentarily before replacing the 0 with 1 which is not smooth for the UI



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source