布局期间抛出以下断言:底部 X 像素溢出的 RenderFlex

发布于 2025-01-12 12:02:27 字数 5614 浏览 4 评论 0原文

您好,我是 flutter 新手,我正在尝试构建一个简单的登录/注册屏幕,但每次弹出键盘时,它都会在相关小部件列上出现此渲染错误,已经更改了 resizeToAvoidBottomInset为 false 但我希望框架滚动,为此我尝试用 ListViewSingleChildScrollView 包装每个小部件,但似乎没有任何东西可以修复它或直接给我一些其他错误,我没有看到什么?

感谢您的帮助!

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          padding: const EdgeInsets.symmetric(
            horizontal: 32,
          ),
          width: double.infinity,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Flexible(child: Container(), flex: 2),
              //----------------------------------------------------------------
              //---------------------------logo image---------------------------
              //----------------------------------------------------------------
              SvgPicture.asset(
                'assets/logo.svg',
                color: Colors.red[800],
                height: 100,
              ),
              //spacing box
              const SizedBox(height: 55),
              //----------------------------------------------------------------
              //------------------------text for email--------------------------
              //----------------------------------------------------------------
              textFieldIn(
                textEditingController: _emailController,
                hintText: 'Enter your Email',
                textInputType: TextInputType.emailAddress,
              ),
              //spacing box
              const SizedBox(height: 21),
              //----------------------------------------------------------------
              //-----------------------text for password------------------------
              //----------------------------------------------------------------
              textFieldIn(
                textEditingController: _passwordController,
                hintText: 'Enter your Password',
                textInputType: TextInputType.text,
                isPass: true,
              ),
              //spacing box
              const SizedBox(height: 13),
              //----------------------------------------------------------------
              //-----------------------------button-----------------------------
              //----------------------------------------------------------------
              InkWell(
                onTap: () async {
                  setState(() {
                    _isLoading = true;
                  });
                  String result = await authentication().logInUser(
                    email: _emailController.text,
                    password: _passwordController.text,
                  );
                  print(result);
                  if (result != 'Success') {
                    showSnackBar(result, context);
                  } else if (result == 'Success') {
                    Navigator.of(context).pushReplacement(
                      MaterialPageRoute(
                        builder: (context) => const responsiveScreen(
                          mobileLayout: mobileScreen(),
                          webLayout: webScreen(),
                        ),
                      ),
                    );
                  }
                },
                child: Container(
                  child: const Text('Log In'),
                  width: double.infinity,
                  alignment: Alignment.center,
                  padding: const EdgeInsets.symmetric(vertical: 13),
                  decoration: const ShapeDecoration(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(
                        Radius.circular(4),
                      ),
                    ),
                    color: Colors.red,
                  ),
                ),
              ),
              //spacing box
              const SizedBox(height: 8),
              Flexible(
                child: Container(),
                flex: 2,
              ),
              //----------------------------------------------------------------
              //---------------------------signing up---------------------------
              //----------------------------------------------------------------
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    child: const Text("Don't have an account? "),
                    padding: const EdgeInsets.symmetric(
                      vertical: 8,
                    ),
                  ),
                  GestureDetector(
                    onTap: () {
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => const signUpScreen(),
                        ),
                      );
                    },
                    child: Container(
                      child: const Text(
                        "Sign Up",
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      padding: const EdgeInsets.symmetric(
                        vertical: 8,
                      ),
                    ),
                  ),
                ],
              ),
              //spacing box
              const SizedBox(height: 34),
            ],
          ),
        ),
      ),
    );
  }

Hi I'm new to flutter and im trying to build a simple sign in/sign up screen but every time the keyboard pops up it keeps getting this render error on the relevant widget Column, already changed de resizeToAvoidBottomInset to false but I would like the frame to scroll, for this I've tried wrapping every widget with either ListView or SingleChildScrollView but nothing seems to fix it or straight up give me some other error, what am I not seeing?

Thanks for the help!

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          padding: const EdgeInsets.symmetric(
            horizontal: 32,
          ),
          width: double.infinity,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Flexible(child: Container(), flex: 2),
              //----------------------------------------------------------------
              //---------------------------logo image---------------------------
              //----------------------------------------------------------------
              SvgPicture.asset(
                'assets/logo.svg',
                color: Colors.red[800],
                height: 100,
              ),
              //spacing box
              const SizedBox(height: 55),
              //----------------------------------------------------------------
              //------------------------text for email--------------------------
              //----------------------------------------------------------------
              textFieldIn(
                textEditingController: _emailController,
                hintText: 'Enter your Email',
                textInputType: TextInputType.emailAddress,
              ),
              //spacing box
              const SizedBox(height: 21),
              //----------------------------------------------------------------
              //-----------------------text for password------------------------
              //----------------------------------------------------------------
              textFieldIn(
                textEditingController: _passwordController,
                hintText: 'Enter your Password',
                textInputType: TextInputType.text,
                isPass: true,
              ),
              //spacing box
              const SizedBox(height: 13),
              //----------------------------------------------------------------
              //-----------------------------button-----------------------------
              //----------------------------------------------------------------
              InkWell(
                onTap: () async {
                  setState(() {
                    _isLoading = true;
                  });
                  String result = await authentication().logInUser(
                    email: _emailController.text,
                    password: _passwordController.text,
                  );
                  print(result);
                  if (result != 'Success') {
                    showSnackBar(result, context);
                  } else if (result == 'Success') {
                    Navigator.of(context).pushReplacement(
                      MaterialPageRoute(
                        builder: (context) => const responsiveScreen(
                          mobileLayout: mobileScreen(),
                          webLayout: webScreen(),
                        ),
                      ),
                    );
                  }
                },
                child: Container(
                  child: const Text('Log In'),
                  width: double.infinity,
                  alignment: Alignment.center,
                  padding: const EdgeInsets.symmetric(vertical: 13),
                  decoration: const ShapeDecoration(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(
                        Radius.circular(4),
                      ),
                    ),
                    color: Colors.red,
                  ),
                ),
              ),
              //spacing box
              const SizedBox(height: 8),
              Flexible(
                child: Container(),
                flex: 2,
              ),
              //----------------------------------------------------------------
              //---------------------------signing up---------------------------
              //----------------------------------------------------------------
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    child: const Text("Don't have an account? "),
                    padding: const EdgeInsets.symmetric(
                      vertical: 8,
                    ),
                  ),
                  GestureDetector(
                    onTap: () {
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => const signUpScreen(),
                        ),
                      );
                    },
                    child: Container(
                      child: const Text(
                        "Sign Up",
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      padding: const EdgeInsets.symmetric(
                        vertical: 8,
                      ),
                    ),
                  ),
                ],
              ),
              //spacing box
              const SizedBox(height: 34),
            ],
          ),
        ),
      ),
    );
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2025-01-19 12:02:27

首先,建议将 Scaffold 包裹在 SafeArea 内,而不是其他方式。现在关于您的问题,将第一个 Container 包装在三个或您的 Column 中,这样

SizedBox(
   height: MediaQuery.of(context).size.height,
   child: SingleChildScrollView (
      child: ...
   )
);

应该可以解决问题。

First, for advice wrap Scaffold inside SafeArea not the other way. Now about your question, wrapping the first Container in the three or your Column like this

SizedBox(
   height: MediaQuery.of(context).size.height,
   child: SingleChildScrollView (
      child: ...
   )
);

should resolve the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文