如何解决SingleChildScrollView使UI变为白色
我试图使我的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,)));
},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,child: Text(
"${widget.categoryName}",))
],))
],);
}
}
解决方法
您的用户界面变白的原因是SingleChildScrollView
允许其子级占用尽可能多的空间。在您的Column
中,您的一个孩子是Expanded
,Expanded
试图占用尽可能多的空间。因此,您正在使UI占用无限量的空间。这就是为什么您看到白色屏幕的原因。 此处的解决方案是删除Expanded
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。