ScrollView RenderFlex 溢出 - Flutter

ScrollView RenderFlex overflow - Flutter

我是 Flutter 的新手,一直在尝试克隆需要滚动架构的屏幕。
这是我正在处理的屏幕 link。 https://i.stack.imgur.com/1OW2b.png
代码如下。
PS:忽略不完整的字段。一旦获得滚动视图,我将在之后添加功能。

Scaffold(
      body: Column(
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.fromLTRB(15.0, 40.0, 15.0, 0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: const <Widget>[
                        Icon(Icons.menu),
                        Image(),       //Asset image
                      ],
                    ),
                    Row(
                      children: <Widget>[
                        const Icon(Icons.notifications_none),
                        const SizedBox(width: 27.0),
                        CircleAvatar(
                          child: Text("JM"),
                        ),
                      ],
                    )
                  ],
                ),
                Row(
                  children: const <Widget>[
                    Icon(Icons.arrow_back),
                    SizedBox(width: 20.0),
                    Text("Public page"),
                  ],
                ),
                const SizedBox(
                  height: 20.0,
                ),
                const Text("  Please fill the form following the proper order."),
                const SizedBox(height: 10.0),

                OverviewWidget(), //Widget with lots of TextFormField
                SizedBox(height: 10.0),
                DescriptionWidget(), //Widget with lots of TextFormField

              ],
            ),
          ),
          Align([enter image description here][1]
            alignment: Alignment.bottomCenter,
            child: GestureDetector(
              onTap: () {
                print("Hello");
              },
              child: Container(
                height: 130.0,
                width: double.infinity,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: Colors.white,
                  boxShadow: [
                    BoxShadow(
                      color: Colors.grey.shade400,
                      blurRadius: 10,
                      spreadRadius: 1,
                    )
                  ],
                ),
                child: Container(
                  margin: const EdgeInsets.only(top: 10.0, bottom: 30.0),
                  decoration: BoxDecoration(
                    color: Colors.green.shade400,
                    borderRadius: BorderRadius.circular(35),
                  ),
                  child: const Padding(
                    padding: EdgeInsets.symmetric(
                      vertical: 15.0,
                      horizontal: 150.0,
                    ),
                    child: Text(
                      "Save",
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 17,
                          fontWeight: FontWeight.w600),
                    ),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );

到目前为止,我只创建了 OverviewDescription 小部件,但我已经收到 RenderFlex overflow 错误。我尝试用 SingleChildScrollView 小部件包装第一个 Column 小部件,但可以注意到底部的 Save 按钮应该保持固定。我尝试用 Stack 小部件而不是 Column 小部件包装整个小部件,但它也没有帮助。我也使用了 ListView 小部件,但得到了相同的结果。
我应该怎么做才能实现此视图?

考虑用 Expanded 小部件包装 Column

你也可以查看这个 flutter 文档。它详细解决了这个常见问题。 https://flutter.dev/docs/testing/common-errors

我猜你拥有所有元素,但没有完全按照需要使用它们。

您的屏幕由两个重要布局组成:

  • 堆栈(包含位于可滚动小部件顶部的按钮)
  • 可滚动小部件

堆栈必须是堆栈,可滚动可以是任何东西,但在您的情况下,SingleChildScrollView+Column 似乎是最佳选择。

具体实现如下:

Scaffold(
  body: Stack(
    children: <Widget>[
      Padding(
        padding: const EdgeInsets.fromLTRB(15.0, 40.0, 15.0, 0),
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.only(bottom: 100.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Icon(Icons.menu),
                        Container(
                          height: 100,
                          width: 100,
                          color: Colors.redAccent,
                        ),
                        //Asset image
                      ],
                    ),
                    Row(
                      children: <Widget>[
                        const Icon(Icons.notifications_none),
                        const SizedBox(width: 27.0),
                        CircleAvatar(
                          child: Text("JM"),
                        ),
                      ],
                    )
                  ],
                ),
                Row(
                  children: const <Widget>[
                    Icon(Icons.arrow_back),
                    SizedBox(width: 20.0),
                    Text("Public page"),
                  ],
                ),
                const SizedBox(
                  height: 20.0,
                ),
                const Text("  Please fill the form following the proper order."),
                const SizedBox(height: 10.0),

                Container(
                  height: 400,
                  color: Colors.blueAccent,
                ), //Widget with lots of TextFormField
                SizedBox(height: 10.0),
                Container(
                  height: 400,
                  color: Colors.greenAccent,
                ), //Widget with lots of TextFormField
              ],
            ),
          ),
        ),
      ),
      Align(
        alignment: Alignment.bottomCenter,
        child: GestureDetector(
          onTap: () {
            print("Hello");
          },
          child: Container(
            height: 130.0,
            width: double.infinity,
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Colors.grey.shade400,
                  blurRadius: 10,
                  spreadRadius: 1,
                )
              ],
            ),
            child: Container(
              margin: const EdgeInsets.only(top: 10.0, bottom: 30.0),
              decoration: BoxDecoration(
                color: Colors.green.shade400,
                borderRadius: BorderRadius.circular(35),
              ),
              child: const Padding(
                padding: EdgeInsets.symmetric(
                  vertical: 15.0,
                  horizontal: 150.0,
                ),
                child: Text(
                  "Save",
                  style: TextStyle(
                      color: Colors.white, fontSize: 17, fontWeight: FontWeight.w600),
                ),
              ),
            ),
          ),
        ),
      ),
    ],
  ),
)

请注意,您必须在 SingleChildScrollView 内放置底部填充以考虑按钮。这对您来说很好,因为按钮具有静态高度。但是,如果您需要更花哨的东西,您可能需要按照@Csisanyi 的建议检查

Scaffold(
        body: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.fromLTRB(15.0, 40.0, 15.0, 0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: <Widget>[
                            Icon(Icons.menu),
                            // Image(), //Asset image

                            Image.asset(
                              'assets/ocean.jpg',
                              height: kToolbarHeight,

                              /// make sure of image height
                              fit: BoxFit.fitHeight,
                            ),
                          ],
                        ),
                        Row(
                          children: <Widget>[
                            const Icon(Icons.notifications_none),
                            const SizedBox(width: 27.0),
                            CircleAvatar(
                              child: Text("JM"),
                            ),
                          ],
                        )
                      ],
                    ),
                    Row(
                      children: const <Widget>[
                        Icon(Icons.arrow_back),
                        SizedBox(width: 20.0),
                        Text("Public page"),
                      ],
                    ),
                    const SizedBox(
                      height: 20.0,
                    ),
                    const Text(
                        "  Please fill the form following the proper order."),
                    const SizedBox(height: 10.0),

                    //todo: OverviewWidget(), //Widget with lots of TextFormField
                    ...List.generate(22, (index) {
                      return TextField(
                        decoration: InputDecoration(hintText: "1st $index"),
                      );
                    }),
                    SizedBox(height: 10.0),
                    //todo: DescriptionWidget(), //Widget with lots of TextFormField
                    ...List.generate(22, (index) {
                      return TextField(
                        decoration: InputDecoration(hintText: "2st $index"),
                      );
                    }),
                  ],
                ),
              ),
              Align(
                alignment: Alignment.bottomCenter,
                child: GestureDetector(
                  onTap: () {
                    print("Hello");
                  },
                  child: Container(
                    height: 130.0,
                    width: double.infinity,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      boxShadow: [
                        BoxShadow(
                          color: Colors.grey.shade400,
                          blurRadius: 10,
                          spreadRadius: 1,
                        )
                      ],
                    ),
                    child: Container(
                      margin: const EdgeInsets.only(top: 10.0, bottom: 30.0),
                      decoration: BoxDecoration(
                        color: Colors.green.shade400,
                        borderRadius: BorderRadius.circular(35),
                      ),
                      child: const Padding(
                        padding: EdgeInsets.symmetric(
                          vertical: 15.0,
                          horizontal: 150.0,
                        ),
                        child: Text(
                          "Save",
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 17,
                              fontWeight: FontWeight.w600),
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),