SingleChildScrollView使UI变为白色

时间:2020-08-31 08:56:00

标签: flutter scroll

我试图使我的UI滚动,但是当我添加SingleChildScrollView时,我得到的白色屏幕根本不显示任何内容。我应该从一开始就删除该列?使用容器吗?我已经在互联网上搜索了,但我没有不知道要添加什么。 这是我的代码,请告诉我可以删除或添加哪些内容以使其正常工作..

class _UserProfilesState extends State<UserProfiles> {

  @override
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Expanded(
                child: Stack(
              children: <Widget>[
                Padding(
                    padding:
                        EdgeInsets.symmetric(horizontal: 10.0, vertical: 40.0),
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          IconButton(
                            icon: Icon(Icons.arrow_back),
                            iconSize: 30.0,
                            color: Colors.black,
                            onPressed: () => Navigator.pop(context),
                          ),
                        ])),
                Positioned(
                  left: 24,
                  top: MediaQuery.of(context).size.height / 6.5 - 28,
                  child: Container(
                    height: 84,
                    width: 84,

                    //profilepic
                    child: CircleAvatar(
                      radius: 10,
                      backgroundImage: NetworkImage(widget.avatarUrl != null
                          ? widget.avatarUrl
                          : "https://icon-library.com/images/add-image-icon/add-image-icon-14.jpg"),
                    ),
                  ),
                ),
                Positioned(
                  right: 24,
                  top: MediaQuery.of(context).size.height / 6.5 + 16,
                  child: Row(
                    children: <Widget>[
                      Container(
                        height: 32,
                        width: 100,
                        child: RaisedButton(
                            onPressed: () {
                              Navigator.of(context).push(MaterialPageRoute(
                                  builder: (context) => ChatScreen(
                                        serviceProviderId:
                                            widget.serviceProviderId,
                                        userName: widget.userName,
                                        avatarUrl: widget.avatarUrl,
                                      )));
                            },
                            color: Colors.black,
                            textColor: Colors.white,
                            child: Text(
                              "Message",
                              style: TextStyle(fontWeight: FontWeight.bold),
                            )),
                      ),
                      SizedBox(
                        width: 16,
                      ),
                      Container(
                        height: 32,
                        width: 32,
                        decoration: BoxDecoration(
                            image: DecorationImage(
                                image: NetworkImage(
                                    "https://lh3.googleusercontent.com/Kf8WTct65hFJxBUDm5E-EpYsiDoLQiGGbnuyP6HBNax43YShXti9THPon1YKB6zPYpA"),
                                fit: BoxFit.cover),
                            shape: BoxShape.circle,
                            color: Colors.blue),
                      ),
                    ],
                  ),
                ),
                Positioned(
                    left: 24,
                    top: MediaQuery.of(context).size.height / 4.3,
                    bottom: 0,
                    right: 0,
                    child: Container(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text(widget.userName,
                              style: TextStyle(
                                color: Colors.black,
                                fontWeight: FontWeight.bold,
                                fontSize: 22,
                              )),
                          SizedBox(
                            height: 4,
                          ),
                          Padding(
                              padding: const EdgeInsets.all(1.0),
                              child: Text(
                                widget.address == "default"
                                    ? "No Address yet"
                                    : "${widget.address}",
                                style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 12,
                                ),
                              )),
                          Padding(
                              padding: const EdgeInsets.all(1.0),
                              child: Text(
                                "${widget.categoryName}",
                                style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 12,
                                ),
                              )),
                        ],
                      ),
                    ))
              ],
            ))
          ],
        ),
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

您的用户界面变白的原因是SingleChildScrollView允许其子级占用尽可能多的空间。在您的Column中,您的一个孩子是ExpandedExpanded试图占用尽可能多的空间。因此,您正在使UI占用无限量的空间。这就是为什么您看到白色屏幕的原因。 此处的解决方案是删除Expanded