在“列”窗口小部件内容中使用SingleChildScrollview不会滚动

时间:2020-01-08 05:41:29

标签: flutter dart cross-platform

Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: Colors.white,
      body: Container(
        child: Column(
          children: <Widget>[
            Stack(
              fit: StackFit.loose,
              children: <Widget>[
                HeadersVC(),
                Container(
                  margin: EdgeInsets.only(top: 40.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      FlatButton(
                        splashColor: Colors.transparent,
                        highlightColor: Colors.transparent,
                        onPressed: () {
                          Navigator.pop(context);
                        },
                        child: Icon(
                          Icons.arrow_back,
                          size: 30,
                          color: Colors.white,
                        ),
                      ),
                      Text(
                        widget.headertitleladderPre,
                        style: TextStyle(
                            fontSize: 22.0,
                            color: Colors.white,
                            fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                )
              ],
            ),
            SingleChildScrollView(
              padding: EdgeInsets.only(top: 20.0, left: 30.0, right: 30.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.only(top: 10.0),
                  ),
                  //******************************************** Date Picker  */
                  TextFormField(
                    onTap: () async {
                      FocusScope.of(context).requestFocus(new FocusNode());
                      _selectDate(context);
                    },
                    decoration: InputDecoration(
                        enabledBorder: UnderlineInputBorder(
                            borderSide:
                                BorderSide(color: Colors.black26, width: 1.5)),
                        contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
                        labelText: formatDate(formatedDate),
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black),
                        suffixIcon: new Padding(
                          padding: const EdgeInsets.only(
                              top: 0.0, left: 0.0, right: 0.0, bottom: 0.0),
                          child: SizedBox(
                            height: 15,
                            child: Icon(
                              Icons.calendar_today,
                              color: Colors.red,
                            ),
                          ),
                        )),
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 0.0, top: 10.0),
                  ),
                  //******************************************** DropDown Button  */
                  Container(
                    child: DropdownButton(
                      underline: Container(
                        height: 1.0,
                        decoration: const BoxDecoration(
                            border: Border(
                                bottom: BorderSide(
                                    color: Colors.black26, width: 1.5))),
                      ),
                      value: _selectedladleno,
                      items: _dropDownladleItems,
                      onChanged: changedDropDownItem,
                      isExpanded: true,
                      isDense: false,
                      icon: Icon(
                        Icons.arrow_drop_down,
                        color: Colors.red,
                      ),
                      iconSize: 30,
                      elevation: 12,
                      style: TextStyle(
                        fontSize: 15,
                      ),
                    ),
                  ),
                  //******************************************** Radio Button  */
                  ButtonBar(
                    alignment: MainAxisAlignment.start,
                    buttonPadding: EdgeInsets.only(left: 0.0),
                    children: <Widget>[
                      Radio(
                        groupValue: _character,
                        onChanged: (SingingCharacter value) {
                          setState(() {
                            _character = value;
                            print(_character);
                          });
                        },
                        value: SingingCharacter.New,
                        activeColor: Colors.red,
                      ),
                      Text(
                        "New",
                        style: TextStyle(fontSize: 13.0),
                      ),
                      Radio(
                        groupValue: _character,
                        onChanged: (SingingCharacter value) {
                          setState(() {
                            _character = value;
                            print(_character);
                          });
                        },
                        value: SingingCharacter.Repair,
                        activeColor: Colors.red,
                      ),
                      Text(
                        "Repair",
                        style: TextStyle(fontSize: 13.0),
                      ),
                      Radio(
                        groupValue: _character,
                        onChanged: (SingingCharacter value) {
                          setState(() {
                            _character = value;
                            print(_character.toString());
                          });
                        },
                        value: SingingCharacter.OnlyMachineChange,
                        activeColor: Colors.red,
                      ),
                      Text(
                        "Machine Change",
                        style: TextStyle(fontSize: 13.0),
                      ),
                    ],
                  ),
                  //******************************************** Machine Number  */
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Machine Number *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  ),
                  TextFormField(
                    decoration: InputDecoration(
                        labelText: "Well Block Party *",
                        labelStyle: TextStyle(
                            fontFamily: "Montserrat", color: Colors.black)),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

我遇到类似这样的错误:

执行热重装...⣟颤抖:REN渲染库引起的异常CA ════════════════════════════ 颤动:布局期间引发了以下断言: 抖动:RenderFlex在底部溢出158像素。 扑: 扑:相关的引起错误的小部件是: flutter:列文件://://Users/baps/Projects/Flutter%20Projects/TRLApp/trlapp/lib/ladlePreheating.dart:64:16 扑: 颤动:溢出的RenderFlex的方向为Axis.vertical。 抖动:溢出的RenderFlex边缘在渲染中用黄色和 扑:黑色条纹。这通常是因为内容对于RenderFlex而言太大。 颤动:考虑应用弹性系数(例如,使用扩展小部件)来强制 颤动:RenderFlex可以容纳在可用空间内,而不是按照其自然大小进行调整。 颤动:这被认为是错误情况,因为它表明存在不能被删除的内容 扑扑:见过。如果内容合法大于可用空间,请考虑使用 flutter:将ClipRect小部件放入Flex之前,或使用可滚动容器而不是Flex, 扑:像一个ListView。 颤振:有问题的特定RenderFlex是:RenderFlex#4bdfd relayoutBoundary = up1溢出: 颤动:需要合成 flutter:创建者:列←容器←_BodyBuilder←MediaQuery←LayoutId-[<_ ScaffoldSlot.body>]← 颤振:CustomMultiChildLayout←AnimatedBuilder←DefaultTextStyle←AnimatedDefaultTextStyle← 颤动:_InkFeatures- [GlobalKey#9c17c墨水渲染器]←NotificationListener← 颤动:PhysicalModel←⋯ flutter:parentData:offset = Offset(0.0,0.0); id = _ScaffoldSlot.body(可以使用大小) 颤动:约束:BoxConstraints(0.0 <= w <= 414.0,0.0 <= h <= 736.0) 扑动:大小:大小(414.0,736.0) 颤动:方向:垂直 颤动:mainAxisAlignment:开始 扑动:mainAxisSize:最大 颤动:crossAxisAlignment:中心 颤动:垂直方向:向下 颤动◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤ ◢◤ 颤动══════════════════════════════════════════════════ ══

4 个答案:

答案 0 :(得分:3)

由于无法将ScrollView扩展为Column容器,因此不知道需要占用多少空间,因此,它计算的大小大于屏幕大小。

因此只需将其扩展到其中即可:

...
Expanded(
                child: SingleChildScrollView(
                  padding:...

output

答案 1 :(得分:0)

解决方案:您需要在列之前使用SingleChildScrollView。如果要保持单独的堆栈部分,可以使用CustomScrollView。 CustomScrollView

  Widget build(BuildContext context) {
return Scaffold(
    resizeToAvoidBottomInset: false,
    backgroundColor: Colors.white,
    body: SingleChildScrollView(
      padding: EdgeInsets.only(top: 20.0, left: 30.0, right: 30.0),
      child: Container(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Stack(
              fit: StackFit.loose,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.only(top: 40.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      FlatButton(
                        splashColor: Colors.transparent,
                        highlightColor: Colors.transparent,
                        onPressed: () {
                          Navigator.pop(context);
                        },
                        child: Icon(
                          Icons.arrow_back,
                          size: 30,
                          color: Colors.white,
                        ),
                      ),
                      Text(
                        "headertitleladderPre",
                        style: TextStyle(
                            fontSize: 22.0,
                            color: Colors.white,
                            fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                )
              ],
            ),
            Padding(
              padding: EdgeInsets.only(top: 10.0),
            ),
            //******************************************** Date Picker  */
            TextFormField(
              onTap: () async {},
              decoration: InputDecoration(
                  enabledBorder: UnderlineInputBorder(
                      borderSide:
                          BorderSide(color: Colors.black26, width: 1.5)),
                  contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
                  labelText: "formatedDate",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black),
                  suffixIcon: new Padding(
                    padding: const EdgeInsets.only(
                        top: 0.0, left: 0.0, right: 0.0, bottom: 0.0),
                    child: SizedBox(
                      height: 15,
                      child: Icon(
                        Icons.calendar_today,
                        color: Colors.red,
                      ),
                    ),
                  )),
            ),
            Padding(
              padding: EdgeInsets.only(left: 0.0, top: 10.0),
            ),
            //******************************************** DropDown Button  */
            Container(
              child: DropdownButton<String>(
                value: dropdownValue,
                icon: Icon(Icons.arrow_downward),
                iconSize: 24,
                elevation: 16,
                style: TextStyle(color: Colors.deepPurple),
                underline: Container(
                  height: 2,
                  color: Colors.deepPurpleAccent,
                ),
                onChanged: (String newValue) {},
                items: <String>['One', 'Two', 'Free', 'Four']
                    .map<DropdownMenuItem<String>>((String value) {
                  return DropdownMenuItem<String>(
                    value: value,
                    child: Text(value),
                  );
                }).toList(),
              ),
            ),
            //******************************************** Radio Button  */
            ButtonBar(
              alignment: MainAxisAlignment.start,
              buttonPadding: EdgeInsets.only(left: 0.0),
              children: <Widget>[
                Text("Radio Here"),
                Text(
                  "New",
                  style: TextStyle(fontSize: 13.0),
                ),
                Text("One More Radio Here"),
                Text(
                  "Repair",
                  style: TextStyle(fontSize: 13.0),
                ),
                Text("One More Radio Here"),
                Text(
                  "Machine Change",
                  style: TextStyle(fontSize: 13.0),
                ),
              ],
            ),
            //******************************************** Machine Number  */
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Machine Number *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            ),
            TextFormField(
              decoration: InputDecoration(
                  labelText: "Well Block Party *",
                  labelStyle: TextStyle(
                      fontFamily: "Montserrat", color: Colors.black)),
            )
          ],
        ),
      ),
    ));

}

答案 2 :(得分:0)

SingleChildScrollView应该用Column包裹:

Scaffold(
  resizeToAvoidBottomInset: false,
  backgroundColor: Colors.white,
  body: Container(
    child: SingleChildScrollView( // <--- Put it here.
        child: Column( // <--- Your Column.

答案 3 :(得分:0)

避免使用

孩子:ConstrainedBox( 约束:BoxConstraints()),

当我删除这个小部件渲染错误时,SingleChildScrollView 侧边消失了。

我的布局示例代码。

@override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: kBackgroundColorGray,
      appBar: commonAppBar,
        body: SafeArea(
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [

             ],
            ),
          ),
        )
    );
  }