TextFormField gains focus current page gets closed

833 Views Asked by At

In my login page both username and password fields exist when any of the field gets focus keyboard displayed and suddenly the page gets closed immediately. Analysed and found that this issue is happening only when I use the screenutil package init method before my material app. If I remove this it is working fine.

Any suggestions would really help. Thanks in advance.

app_start.dart file:

ScreenUtilInit(
                  designSize: const Size(375, 667),
                  builder: (_, child) {
                    return MaterialApp()
});

login_page.dart

Form(
      key: model.loginFormKey,
      child: Column(
        children: [
          PrimaryTextField(
            controller: model.emailAddressController,
            label: Strings.of(context).email_address,
            keyBoardType: TextInputType.emailAddress,
            validator: Validator.emailValidator,
          ),
          PrimaryTextField(
            controller: model.passwordController,
            label: Strings.of(context).password,
            validator: Validator.pwdValidator,
          ),
         ]
)
)

Primary_text_field

class _PrimaryTextFieldState extends State<PrimaryTextField> {
  ValueNotifier<bool> validateForm = ValueNotifier<bool>(false);

  @override
  Widget build(final BuildContext context) => ValueListenableBuilder<bool>(
        valueListenable: validateForm,
        builder: (
          context,
          listenValue,
          child,
        ) {
          return TextFormField(
            focusNode: widget.focusNode,
            autocorrect: false,
            maxLines: widget.maxLines ?? 1,
            controller: widget.controller,
            onChanged: (value) {
              validateForm.value =
                  widget.validator!(widget.controller.text) != null;
            },
            inputFormatters: widget.inputFormatters,
            validator: widget.validator,
            autovalidateMode: AutovalidateMode.onUserInteraction,
            keyboardType: widget.keyBoardType,
            obscureText: widget.isPassword,
            decoration: InputDecoration(
              labelText: widget.label,
              floatingLabelStyle: listenValue
                  ? AppTextStyle().notificationsErrorBodyXS
                  : AppTextStyle().bodyNeutralTwoLeftLowEmphasis500,
              labelStyle: AppTextStyle().bodyNeutralTwoLeftLowEmphasis500,
              errorStyle: AppTextStyle().notificationsErrorBodyXS,
              suffixIconConstraints: const BoxConstraints(
                minHeight: 14,
                minWidth: 20,
              ),
              suffixIcon: widget.isEyeSymbol
                  ? InkWell(
                      onTap: widget.onSuffixTap,
                      child: widget.isPassword
                          ? Padding(
                              padding: const EdgeInsets.only(
                                right: 10,
                              ),
                              child: AppSvg.asset(
                                AssetIcons.visibilityNotN1,
                              ),
                            )
                          : Padding(
                              padding: const EdgeInsets.only(
                                right: 10,
                              ),
                              child: AppSvg.asset(
                                AssetIcons.visibilityN1,
                              ),
                            ))
                  : const SizedBox(),
              errorMaxLines: 2,
              fillColor: widget.bgColor ?? AppColorStyle().neutral_500_10,
              filled: true,
              contentPadding: EdgeInsets.symmetric(
                horizontal: 16.w,
                vertical: widget.verticalPadding ?? 16.h,
              ),
              focusedBorder: UnderlineInputBorder(
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(
                    widget.borderRadius ?? 4.r,
                  ),
                  topRight: Radius.circular(
                    widget.borderRadius ?? 4.r,
                  ),
                ),
                borderSide: BorderSide(
                  color: AppColorStyle().neutral_700,
                  width: 2.w,
                ),
              ),
              enabledBorder: UnderlineInputBorder(
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(
                    widget.borderRadius ?? 4.r,
                  ),
                  topRight: Radius.circular(
                    widget.borderRadius ?? 4.r,
                  ),
                ),
                borderSide: BorderSide(
                  color: AppColorStyle().neutral_500,
                ),
              ),
            
              
            ),
          );
        },
      );
}

Logs:

onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager(13938): showSoftInput() view=io.flutter.embedding.android.FlutterView{fe12c43 VFE...... .F....ID 0,0-1080,2274 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/EGL_emulation(13938): app_time_stats: avg=46.56ms min=2.02ms max=709.37ms count=22
D/InsetsController(13938): show(ime(), fromIme=true)
I/ImeTracker(13938): com.example.dev:1d3363d3: onRequestHide at ORIGIN_CLIENT_HIDE_SOFT_INPUT reason HIDE_SOFT_INPUT
W/WindowOnBackDispatcher(13938): sendCancelIfRunning: isInProgress=falsecallback=ImeCallback=ImeOnBackInvokedCallback@243525502 Callback=android.window.IOnBackInvokedCallback$Stub$Proxy@ce0499f
I/ImeTracker(13938): db2c8a5c: onCancelled at PHASE_CLIENT_ANIMATION_CANCEL
D/EGL_emulation(13938): app_time_stats: avg=4734.11ms min=1.42ms max=89123.80ms count=19
D/EGL_emulation(13938): app_time_stats: avg=66.93ms min=7.93ms max=334.65ms count=15
I/ImeTracker(13938): com.example.dev:87b7a37: onRequestHide at ORIGIN_CLIENT_HIDE_SOFT_INPUT reason HIDE_SOFT_INPUT_BY_INSETS_API
I/ImeTracker(13938): com.example.dev:1d3363d3: onHidden

I'm using clean architecture with mvvm so I have textformfield in my model files so I tried moving it to inside the state class. I tried changing the designSize of the screen util still no difference.

1

There are 1 best solutions below

0
Jack Gomez On

i fix it by rebuild object that i made to recive data from API the problem was i forgot there's list between maps on API , i don't if you have same error but you can check the API and Model that you create and make sure