使用Singlechildview小部件时显示错误-Flutter

5t7ly7z5  于 2022-12-24  发布在  Flutter
关注(0)|答案(2)|浏览(157)

我创建了这个屏幕,现在当我使用键盘输入电子邮件或密码时,它显示溢出错误,按钮元素被隐藏,我无法访问。我搜索并使用SingleChildScrollView,然后整个屏幕消失。我搜索并无法得到正确的答案,所以我发布了这个问题。抱歉,如果已经有解决方案。我找不到它。
登录界面窗口的原始代码:

import 'package:flutter/material.dart';
    import 'package:nazkearn_app/SignScreen/signupscreen.dart';
    import 'package:nazkearn_app/components/fieldform.dart';
    import 'package:unicons/unicons.dart';
    
    class SignInScreen extends StatelessWidget {
      SignInScreen({Key? key}) : super(key: key);
    
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            body: SingleChildScrollView(
              child: Column(
                  children: [
                    const SizedBox(
                      height: 150,
                    ),
                    const Padding(
                        padding: EdgeInsets.only(left: 20.0)),
                    const Center(
                      child: Text("Sign In",
                        style: TextStyle(
                          fontSize: 30,
                          fontWeight: FontWeight.bold,
                        ),),
                    ),
                    Text("Login and continue your journey",
                      style: TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.normal,
                          color: Colors.grey[700]
                      ),),
                    const SizedBox(
                      height: 20,
                    ),
                    const Fieldform(
                        name: "Email",
                        foretext: "Type your email"),
                    const Fieldform(
                        name: "Password",
                        foretext: "Type your Password"),
                    const SizedBox(
                      height: 30,
                    ),
                    const TapButton(
                        text: "Sign in"),
                    const LinkText(
                          normal:"Don't have an Account",
                          link: "Sign in"),
                    const SizedBox(
                      height: 05,
                    ),
                    const Text("Or Else sign with this alternatives",
                    style: TextStyle(
                      fontSize: 16
                    ),
                    ),
                    const SizedBox(
                      height: 30,
                    ),
                    signinbutton_google(),
                    SigninButton_facebook(),
                    SigninButton_twitter(),
                    Spacer(),
                    Row(
                      children: const [
                        Padding(padding: EdgeInsets.only(left: 100,bottom: 30)),
                        Icon(Icons.info_outline),
                        Text("All rights reserved by Naz-kearn Corp",
                          style: TextStyle(
                            fontWeight: FontWeight.w400,
                            fontSize: 12,
                          ),
                        ),
                      ],
                    ),
                    ]
              ),
            ),
        );
      }
    
      Padding SigninButton_twitter() {
        return Padding(
                  padding: const EdgeInsets.only(left: 60,right: 70,
                      top: 20),
                  child: OutlinedButton(
                      onPressed: (){},
                      style: ButtonStyle(
                          shape: MaterialStateProperty.all(RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(18.0),
                              side: const BorderSide(
                                  color: Colors.green
                              )
                          ))
                      ),
                      child: Row(
                        children: const [
                          SizedBox(width: 10),
                          Icon(UniconsLine.twitter,
                              size: 40),
                          SizedBox(
                            width: 10,
                          ),
                          Text("Sign in with twitter",
                            style: TextStyle(
                                fontSize: 20,
                                color: Colors.grey
                            ),),
                        ],
                      )
                  ),
                );
      }
    
      Padding SigninButton_facebook() {
        return Padding(
                  padding: const EdgeInsets.only(left: 60,right: 70,
                  top: 20),
                  child: OutlinedButton(
                      onPressed: (){},
                      style: ButtonStyle(
                          shape: MaterialStateProperty.all(RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(18.0),
                              side: const BorderSide(
                                  color: Colors.green
                              )
                          ))
                      ),
                      child: Row(
                        children: const [
                          SizedBox(width: 10),
                          Icon(UniconsLine.facebook,
                              size: 40),
                          SizedBox(
                            width: 10,
                          ),
                          Text("Sign in with facebook",
                            style: TextStyle(
                                fontSize: 20,
                                color: Colors.grey
                            ),),
                        ],
                      )
                  ),
                );
      }
    
      Padding signinbutton_google() {
        return Padding(
                    padding: const EdgeInsets.only(left: 70,right: 90),
                    child: OutlinedButton(
                        onPressed: (){},
                      style: ButtonStyle(
                        shape: MaterialStateProperty.all(RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(18.0),
                          side: const BorderSide(
                            color: Colors.green
                          )
                        ))
                      ),
                        child: Row(
                          children: const [
                            SizedBox(width: 10),
                            Icon(UniconsLine.google,
                            size: 40),
                            SizedBox(
                              width: 10,
                            ),
                            Text("Sign in with google",
                            style: TextStyle(
                              fontSize: 20,
                              color: Colors.grey
                            ),),
                          ],
                        )
                    ),
                  );
      }
    }
    
    class LinkText extends StatelessWidget {
      const LinkText({Key? key,
        required this.normal,
        required this.link})
          : super(key: key);
      final String normal;
      final String link;
    
      @override
      Widget build(BuildContext context) {
        return Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text("Don't have an Account?",
              style: TextStyle(fontSize: 16),
            ),
            GestureDetector(
              onTap: () {
                Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => const SignupScreen()));
              },
              child: Text("Sign up",
                style: TextStyle(fontSize: 16,
                    color: Colors.red[400]),
              ),
            ),
          ],
        );
      }
    }
    
    class TapButton extends StatelessWidget {
      const TapButton({Key? key, required this.text}) : super(key: key);
      final String text;
    
      @override
      Widget build(BuildContext context) {
        return Padding(
          padding: const EdgeInsets.only(bottom: 30),
          child: SizedBox(
            height: 60,
            width: 200,
            child: ElevatedButton(
              style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.red[400],
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(15)
                  ),
                  shadowColor: Colors.red[600],
                  elevation: 9
              ),
              onPressed: (){},
              child: Text(text),
            ),
          ),
        );
      }
    }

显示的错误为:

    • 在performLayout()过程中抛出以下Assert:渲染框未布局:RenderFlex#fcc9c relayoutBoundary = up11需要-油漆需要-复合-位-更新'软件包:flutter/src/rendering/box.dart':Assert失败:第2001行位置12:"具有大小"**

消失前的实际屏幕为:

添加widget后的界面:

osh3o9ms

osh3o9ms1#

正如eamirho3ein所指出的,你可以使用SizedBox或者Padding widget来代替Spacer来获得一些空间,你也可以在Scaffold上使用bottomNavigationBar:来放置它的底部,但是CustomScrollViewSliverFillRemaining()可能更适合你。

class SignInScreen extends StatelessWidget {
  SignInScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverList(
              delegate: SliverChildListDelegate.fixed([
            /// your others widgets
          ])),
          SliverFillRemaining(
            child: Row(
              //add padding if needed
              crossAxisAlignment: CrossAxisAlignment.end,
              children: const [
                Padding(padding: EdgeInsets.only(left: 100, bottom: 30)),
                Icon(Icons.info_outline),
                Text(
                  "All rights reserved by Naz-kearn Corp",
                  style: TextStyle(
                    fontWeight: FontWeight.w400,
                    fontSize: 12,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
fiei3ece

fiei3ece2#

尝试将SingleChildScrollView和列小部件替换为

Container(
width:  MediaQuery.of(context).size.width, //full width or multiply by 0.8 for 80% width...
height: double.infinity,
     ListView(
     shrinkWrap: true,
     children[...],
     ), //ListView
), //Container

列不可滚动

相关问题