Flutter:未布置RenderBox:RenderRepaintBoundary#58c65 relayoutBoundary = up1 NEEDS-PAINT

时间:2019-12-20 05:20:50

标签: android flutter dart flutter-layout singlechildscrollview

我正在使用def append_guess(n): list_of_numbers = [1, 11, 7, 8, 12, 6, 15, 30, 5, 3, 2] guessed = set() while (n): try: n = int(input("Enter an integer between 1-30 >> ")) if n in list_of_numbers: print("right guess") guessed.add(n) print(guessed) else: print("Wrong Guess - Keep Trying!! ") except: if guessed == set(1, 2, 3, 5, 6, 7, 8, 11, 12, 15, 30): print("Great Job! You have Guessed All numbers") break append_guess(1) 来使屏幕滚动滚动,但是当我添加SingleChildScrollView时,我遇到错误了

SingleChildScrollView

我的代码

RenderBox was not laid out: RenderRepaintBoundary#58c65 relayoutBoundary=up1 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1681 pos 12: 'hasSize

如果我从布局中删除了 class _RegisterPage extends State<RegisterApp> { final _formKey = GlobalKey<FormState>(); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(primarySwatch: Colors.blue, brightness: Brightness.light), darkTheme: ThemeData(brightness: Brightness.dark), home: SafeArea( child: Scaffold( backgroundColor: Colors.white, body: SingleChildScrollView( child: Stack( fit: StackFit.expand, children: <Widget>[ Column( children: <Widget>[ Column( children: <Widget>[ Form( key: _formKey, child: new Theme( data: ThemeData( accentColor: Colors.purple, primaryColor: Colors.blue, inputDecorationTheme: new InputDecorationTheme( labelStyle: new TextStyle( color: Colors.lightBlue, fontSize: 20.0, ))), child: Padding( padding: const EdgeInsets.all(20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ Text( "Register", style: TextStyle( fontSize: 30.0, fontWeight: FontWeight.bold), ), Container( margin: const EdgeInsets.only(top: 20.0), child: Text( "Full Name", style: TextStyle( fontSize: 20.0, ), ), ), TextFormField( style: TextStyle(color: Colors.grey), decoration: new InputDecoration( labelStyle: TextStyle( color: Colors.grey, ), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.grey), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.blue), ), border: UnderlineInputBorder()), keyboardType: TextInputType.emailAddress, ), Container( margin: const EdgeInsets.only(top: 20.0), child: Text( "Address", style: TextStyle( fontSize: 20.0, ), ), ), TextFormField( style: TextStyle(color: Colors.grey), decoration: new InputDecoration( labelStyle: TextStyle( color: Colors.grey, ), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.grey), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.blue), ), border: UnderlineInputBorder()), keyboardType: TextInputType.emailAddress, ), Container( margin: const EdgeInsets.only(top: 20.0), child: Text( "Phone Number", style: TextStyle( fontSize: 20.0, ), ), ), TextFormField( style: TextStyle(color: Colors.grey), decoration: new InputDecoration( labelStyle: TextStyle( color: Colors.grey, ), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.grey), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.blue), ), border: UnderlineInputBorder()), keyboardType: TextInputType.emailAddress, ), Container( margin: const EdgeInsets.only(top: 20.0), child: Text( "Company Name", style: TextStyle( fontSize: 20.0, ), ), ), TextFormField( style: TextStyle(color: Colors.grey), decoration: new InputDecoration( labelStyle: TextStyle( color: Colors.grey, ), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.grey), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.blue), ), border: UnderlineInputBorder()), keyboardType: TextInputType.emailAddress, ), Container( margin: const EdgeInsets.only(top: 20.0), child: Text( "Email Address", style: TextStyle( fontSize: 20.0, ), ), ), TextFormField( style: TextStyle(color: Colors.grey), decoration: new InputDecoration( labelStyle: TextStyle( color: Colors.grey, ), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.grey), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.blue), ), border: UnderlineInputBorder()), keyboardType: TextInputType.emailAddress, ), Container( margin: const EdgeInsets.only(top: 20.0), child: Text( "Password", style: TextStyle( fontSize: 20.0, ), ), ), TextFormField( style: TextStyle(color: Colors.grey), decoration: new InputDecoration( labelStyle: TextStyle( color: Colors.grey, ), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.grey), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.blue), ), border: UnderlineInputBorder()), keyboardType: TextInputType.emailAddress, ), Align( alignment: Alignment.center, child: Container( margin: const EdgeInsets.only(top: 40.0), child: new MaterialButton( textColor: Colors.white, minWidth: 250.0, padding: const EdgeInsets.all(15.0), color: Colors.blue[400], child: new Text( "Register", style: TextStyle( color: Colors.white, // fontWeight: FontWeight.bold, fontSize: 20.0), ), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50.0)), onPressed: () { if (_formKey.currentState .validate()) {} }, splashColor: Colors.redAccent[100], ), ), ) ], ), )), ) ], ) ], ) ], ), ), )), ); } } ,那么打开键盘时我的输出将低于输出

enter image description here

我需要使屏幕可滚动

我已经检查了下面的堆栈溢出链接

如果需要更多信息,请告诉我。提前致谢。您的努力将不胜感激。

整个异常日志

SingleChildScrollView

4 个答案:

答案 0 :(得分:2)

我面临类似的问题

发现Spacer()小部件正在造成UI渲染问题

这不是此问题的解决方案,但可能会对某人有所帮助

谢谢!

答案 1 :(得分:1)

Screenshot 截图

我不明白为什么要使用stack。没有堆栈,它可以正常工作。

  @override
  Widget build(BuildContext context) {

    return Scaffold(

      body: SafeArea(
        child:  SingleChildScrollView(

          child:Column(
                children: <Widget>[
                  Form(
                        key: _formKey,
                        child: new Theme(
                            data: ThemeData(
                                accentColor: Colors.purple,
                                primaryColor: Colors.blue,
                                inputDecorationTheme: new InputDecorationTheme(
                                    labelStyle: new TextStyle(
                                  color: Colors.lightBlue,
                                  fontSize: 20.0,
                                ))),
                            child: Padding(
                              padding: const EdgeInsets.all(20.0),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Text(
                                    "Register",
                                    style: TextStyle(
                                        fontSize: 30.0,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 20.0),
                                    child: Text(
                                      "Full Name",
                                      style: TextStyle(
                                        fontSize: 20.0,
                                      ),
                                    ),
                                  ),
                                  TextFormField(
                                    style: TextStyle(color: Colors.grey),
                                    decoration: new InputDecoration(
                                        labelStyle: TextStyle(
                                          color: Colors.grey,
                                        ),
                                        enabledBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.grey),
                                        ),
                                        focusedBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.blue),
                                        ),
                                        border: UnderlineInputBorder()),
                                    keyboardType: TextInputType.emailAddress,
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 20.0),
                                    child: Text(
                                      "Address",
                                      style: TextStyle(
                                        fontSize: 20.0,
                                      ),
                                    ),
                                  ),
                                  TextFormField(
                                    style: TextStyle(color: Colors.grey),
                                    decoration: new InputDecoration(
                                        labelStyle: TextStyle(
                                          color: Colors.grey,
                                        ),
                                        enabledBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.grey),
                                        ),
                                        focusedBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.blue),
                                        ),
                                        border: UnderlineInputBorder()),
                                    keyboardType: TextInputType.emailAddress,
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 20.0),
                                    child: Text(
                                      "Phone Number",
                                      style: TextStyle(
                                        fontSize: 20.0,
                                      ),
                                    ),
                                  ),
                                  TextFormField(
                                    style: TextStyle(color: Colors.grey),
                                    decoration: new InputDecoration(
                                        labelStyle: TextStyle(
                                          color: Colors.grey,
                                        ),
                                        enabledBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.grey),
                                        ),
                                        focusedBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.blue),
                                        ),
                                        border: UnderlineInputBorder()),
                                    keyboardType: TextInputType.emailAddress,
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 20.0),
                                    child: Text(
                                      "Company Name",
                                      style: TextStyle(
                                        fontSize: 20.0,
                                      ),
                                    ),
                                  ),
                                  TextFormField(
                                    style: TextStyle(color: Colors.grey),
                                    decoration: new InputDecoration(
                                        labelStyle: TextStyle(
                                          color: Colors.grey,
                                        ),
                                        enabledBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.grey),
                                        ),
                                        focusedBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.blue),
                                        ),
                                        border: UnderlineInputBorder()),
                                    keyboardType: TextInputType.emailAddress,
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 20.0),
                                    child: Text(
                                      "Email Address",
                                      style: TextStyle(
                                        fontSize: 20.0,
                                      ),
                                    ),
                                  ),
                                  TextFormField(
                                    style: TextStyle(color: Colors.grey),
                                    decoration: new InputDecoration(
                                        labelStyle: TextStyle(
                                          color: Colors.grey,
                                        ),
                                        enabledBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.grey),
                                        ),
                                        focusedBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.blue),
                                        ),
                                        border: UnderlineInputBorder()),
                                    keyboardType: TextInputType.emailAddress,
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(top: 20.0),
                                    child: Text(
                                      "Password",
                                      style: TextStyle(
                                        fontSize: 20.0,
                                      ),
                                    ),
                                  ),
                                  TextFormField(
                                    style: TextStyle(color: Colors.grey),
                                    decoration: new InputDecoration(
                                        labelStyle: TextStyle(
                                          color: Colors.grey,
                                        ),
                                        enabledBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.grey),
                                        ),
                                        focusedBorder: UnderlineInputBorder(
                                          borderSide:
                                              BorderSide(color: Colors.blue),
                                        ),
                                        border: UnderlineInputBorder()),
                                    keyboardType: TextInputType.emailAddress,
                                  ),
                                  Align(
                                    alignment: Alignment.center,
                                    child: Container(
                                      margin: const EdgeInsets.only(top: 40.0),
                                      child: new MaterialButton(
                                        textColor: Colors.white,
                                        minWidth: 250.0,
                                        padding: const EdgeInsets.all(15.0),
                                        color: Colors.blue[400],
                                        child: new Text(
                                          "Register",
                                          style: TextStyle(
                                              color: Colors.white,
//                                    fontWeight: FontWeight.bold,
                                              fontSize: 20.0),
                                        ),
                                        shape: RoundedRectangleBorder(
                                            borderRadius:
                                                BorderRadius.circular(50.0)),
                                        onPressed: () {
                                          if (_formKey.currentState
                                              .validate()) {}
                                        },
                                        splashColor: Colors.redAccent[100],
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            )),
                      )
                ],
              ) ,
        ),
      )
    );
  }

答案 2 :(得分:1)

您可以使用ListView代替SingleChildScrollView,因此不需要在代码的第一列。

@override
Widget build(BuildContext context) {

return Scaffold(
  body: SafeArea(
    child:  ListView(
            shrinkWrap: true,
            children: <Widget>[
              Form(...),
              ],
              ),),
              );

答案 3 :(得分:0)

这很简单,你只需要删除SingleChildScrollView。 之后向 Scaffold 添加一个属性,即

<块引用>

resizeToAvoidBottomInset: true

它可能对你有用。

<块引用>

示例:

return Scaffold(
      resizeToAvoidBottomInset: true,
      body: SafeArea(child: Container())
    );