列内列的 SingleChildScrollView

Tiz*_*ica 4 flutter flutter-layout singlechildscrollview

在下图中,我想要实现的是让绿色部分Scrollable,因为如果键盘弹出,它不会给我渲染错误。

整个屏幕只是一个Column,其中黄色部分是自定义小部件,绿色部分是Column其中的另一个。

我尝试过不同的解决方案。将整个列包装到 SingleChildScrollView 中,但我希望黄色部分保持固定在顶部。我也尝试过仅将绿色部分包装到 SingleChildScrollView 中,但它不起作用(仍然引发渲染错误)。

我已经看到我可以使用SliverAppBar,但我想使用我的自定义小部件(黄色部分)来实现。

我有点卡住了。

Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            AppBarWidget(height: size.height * 0.15),
            Container(
              height: size.height - size.height * 0.15 - mediaQuery.padding.top,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  EditableAvatarWidget(
                    circleRadius: circleRadius,
                    badge: test,
                    border: Border.all(color: test.mainColor, width: 5),
                  ),
                  Column(
                    children: [
                      Text(
                        "Name Surname",
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 26,
                            color: Global.blackGrey),
                      ),
                      SizedBox(height: 10),
                      Text(
                        "mail@mail.com",
                        style: TextStyle(fontSize: 18, color: Colors.grey),
                      )
                    ],
                  ),
                  Padding(
                    padding: EdgeInsets.symmetric(
                        horizontal: size.width / 6, vertical: 0),
                    child: FlatCustomButton(
                      onPress: () {},
                      background: Global.editProfileButton,
                      text: "Edit profile",
                      textColor: Global.blackGrey,
                      inkwellColor: Colors.black,
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
Run Code Online (Sandbox Code Playgroud)

我可能还会考虑实现一个 ListView (?),但正如你所看到的,我已经在 Column 中设置了 mainAxisAlignment: MainAxisAlignment.spaceAround我的 UI 首选项。

你知道我该如何实现这一目标吗?

TL;DR:仅让属于另一列(整个屏幕)的绿色部分(列)可滚动,并让黄色部分停留在该固定位置

图片

Tiz*_*ica 7

我就是这样解决的。

我将 Green Column 部分封装在Expandedbefore 中,然后封装到SingleChildScrollView. 它完全按照我想要的方式工作。

现在只有绿色部分滚动,黄色部分在键盘出现时保持在固定位置。

 return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            AppBarWidget(
              height: size.height * 0.15,
            ),
            Expanded( //This 
              child: SingleChildScrollView( // and this fixed my issue
                child: Container(
                  height:
                      size.height - size.height * 0.15 - mediaQuery.padding.top,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      EditableAvatarWidget(
                        circleRadius: circleRadius,
                        badge: test,
                        border: Border.all(color: test.mainColor, width: 5),
                      ),
                      Column(
                        children: [
                          Text(
                            "Name Surname",
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: 26,
                                color: Global.blackGrey),
                          ),
                          SizedBox(height: 10),
                          Text(
                            "mail@mail.com",
                            style: TextStyle(fontSize: 18, color: Colors.grey),
                          )
                        ],
                      ),
                      Padding(
                        padding: EdgeInsets.symmetric(
                            horizontal: size.width / 6, vertical: 0),
                        child: FlatCustomButton(
                          onPress: () {},
                          background: Global.editProfileButton,
                          text: "Edit profile",
                          textColor: Global.blackGrey,
                          inkwellColor: Colors.black,
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
Run Code Online (Sandbox Code Playgroud)