繁体   English   中英

SingleChildScrollView 在嵌套列中不起作用。 我的第二列没有使用 SingleChildScrollView 滚动

[英]SingleChildScrollView not working in a nested Column. My second column is not scrolling using SingleChildScrollView

SingleChildScrollView 在嵌套列中不起作用。 我的第二列没有使用 SingleChildScrollView 滚动

Widget build(BuildContext context) {
            return MaterialApp(
              home: Scaffold(
                body: Column(
                  children: [
                    Container(
                      height: 200,
                    ),
                    Container(
                      child: SingleChildScrollView(
                        child: Column(

                          children: [
                            Container(
                              color: Colors.purple,
                              height: 200,
                            ),
                            Container(
                              color: Colors.orange,
                              height: 200,
                            ),
                            Container(
                              color: Colors.red,
                              height: 200,
                            ),
                            Container(
                              color: Colors.yellow,
                              height: 200,
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            );
          }

当我使用 SingleChildScrollView 时,第二列不滚动

尝试将 Container 包装到 Expanded Widget 中。 如果它不起作用,请尝试包装 SingleChildScrollView 或第二个 Column

您应该使用Expanded作为SingleChildScrollView的父级:

Widget build(BuildContext context) {
  return MaterialApp(
    home: Scaffold(
      body: Column(
        children: [
          Container(
            height: 200,
          ),
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    color: Colors.purple,
                    height: 200,
                  ),
                  Container(
                    color: Colors.orange,
                    height: 200,
                  ),
                  Container(
                    color: Colors.red,
                    height: 200,
                  ),
                  Container(
                    color: Colors.yellow,
                    height: 200,
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    ),
  );
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM