flutter - 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,
)));
},
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,
),
)),
],
),
))
],
))
],
),
),
);
}
}
解决方案
你的 UI 变成白色的原因是它SingleChildScrollView
允许它尽可能多地占用空间。在你的Column
,你的一个孩子是Expanded
,Expanded
尽量占据尽可能多的空间。因此,您正在使您的 UI 占用无限量的空间。这就是您看到白屏的原因。这里的解决方案是删除Expanded
.
推荐阅读
- python - 在 pandas 中按时间搜索或分组时间序列数据
- javascript - 未找到此依赖项:./node_modules..../src/App.vue 中的 components/main/Footer
- java - 防止 TableColumn 仅由用户调整大小
- java - Android - HttpURLConnection 不上传多个文件
- mysql - 基于另一个变量的频率分组的变量平均值 (SQL)
- c# - 解析平面数据文件以进行读/写
- python - 如何从文本文件中导入列表(整数)列表并以数学方式处理它们?
- java - 下拉菜单未在 Spring/Java 中显示
- json - 从散列和数组的散列中删除重复的键(并确保任何生成的空散列也被删除)
- python - 如何在烧瓶中高频运行周期性任务?