TextFormField 获得焦点当前页面被关闭

问题描述 投票:0回答:1

在我的登录页面中,当任何字段显示焦点键盘并且突然页面立即关闭时,用户名和密码字段都存在。分析发现,只有当我在材质应用程序之前使用 screenutil 包 init 方法时才会发生此问题。如果我删除它,它就可以正常工作。

任何建议都会很有帮助。预先感谢。

app_start.dart 文件:

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

登录页面.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,
          ),
         ]
)
)

主要文本字段

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,
                ),
              ),
            
              
            ),
          );
        },
      );
}

日志:

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

我正在使用带有 mvvm 的干净架构,因此我的模型文件中有 textformfield,因此我尝试将其移至状态类内部。我尝试更改屏幕实用程序的设计尺寸仍然没有区别。

flutter mvvm clean-architecture textformfield flutter-textformfield
1个回答
0
投票

我通过重建从 API 接收数据的对象来修复它,问题是我忘记了 API 上的地图之间有列表, 如果您有同样的错误,我不会,但您可以检查您创建的 API 和模型并确保

© www.soinside.com 2019 - 2024. All rights reserved.