Flutter:单个子滚动视图在定位的小部件中不起作用
Flutter: single child scroll view is not working within positioned widget
这是我试图使其可滚动的组件的图像:
。当我将单个子滚动视图小部件包装在定位小部件中时,它无法正确滚动。我需要定位小部件才能正确对齐我的组件。我该如何解决这个问题?
Container(
height: 130,
padding: EdgeInsets.all(10),
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.grey[800],
borderRadius: const BorderRadius.all(const Radius.circular(10)),
),
child: Stack(
children: [
Positioned(
top: 30,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ProfilePicScroll(),
),
),
Positioned(
left: 10,
child: Text(
'Following',
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
)),
两个解决方案。
第一个:
将您的 Positioned
小部件更改为 Padding
。
Stack(
children: [
Padding(
padding: const EdgeInsets.only(top: 30.0),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ProfilePicScroll(),
),
),
const Positioned(
left: 10,
child: Text(
'Following',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
],
)
秒:
为所有 Positioned
个参数获取一个值。
Stack(
children: [
Positioned(
top: 30,
left: 0,
right: 0,
bottom: 0,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ProfilePicScroll(),
),
),
const Positioned(
left: 10,
child: Text(
'Following',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
],
)
这是我试图使其可滚动的组件的图像:
Container(
height: 130,
padding: EdgeInsets.all(10),
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.grey[800],
borderRadius: const BorderRadius.all(const Radius.circular(10)),
),
child: Stack(
children: [
Positioned(
top: 30,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ProfilePicScroll(),
),
),
Positioned(
left: 10,
child: Text(
'Following',
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
)),
两个解决方案。
第一个:
将您的 Positioned
小部件更改为 Padding
。
Stack(
children: [
Padding(
padding: const EdgeInsets.only(top: 30.0),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ProfilePicScroll(),
),
),
const Positioned(
left: 10,
child: Text(
'Following',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
],
)
秒:
为所有 Positioned
个参数获取一个值。
Stack(
children: [
Positioned(
top: 30,
left: 0,
right: 0,
bottom: 0,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ProfilePicScroll(),
),
),
const Positioned(
left: 10,
child: Text(
'Following',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
],
)