gpt4 book ai didi

listview - Flutter:ListView.builder 中的 ListView.builder

转载 作者:IT王子 更新时间:2023-10-29 07:12:37 30 4
gpt4 key购买 nike

我想实现一个可滚动(垂直)且其中包含元素的屏幕。所以我把它放在 listview.builder 上。问题是,其中一个元素是另一个水平滚动的 listview.builder。当我实现它时,horizo​​ntal.builder 中的元素没有出现。这是我目前所拥有的:

  @override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: 3,
itemBuilder: (context, position) {
if (position == 0) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
elevation: 1.5,
margin: EdgeInsets.fromLTRB(12.0, 12.0, 12.0, 0.0),
child: Padding(
padding: EdgeInsets.fromLTRB(16.0, 8.0, 16.0, 0.0),
child: Column(
children: <Widget>[
//PICTURE
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Center(
child: Image.asset(
"assets/snek.gif",
fit: BoxFit.scaleDown,
),
),
),

Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Text(
HOME_GIF_TEXT_STR,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18.0),
),
),
],
),
),
);
}
else if (position == 1) //Videos Title
{
return Padding(
padding: EdgeInsets.all(16.0),
child: Text(
"Videos",
style: TextStyle(
fontSize: 36.0,
fontWeight: FontWeight.bold,
color: Colors.black),
),
);
}
else if (position == 2) //Videos
{
Container(
height: 350.0,
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: 3,
controller: scrollController,
scrollDirection: Axis.horizontal,
itemBuilder: (context, position) {
return GestureDetector(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
child: Container(
width: 280.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
children: <Widget>[
Container(
height: 230.0,
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
image: new AssetImage(
"${videoList[position].imgPath}"),
),
),
),
Padding(
padding: EdgeInsets.only(top: 8.0),
child: Text(
"${videoList[position].name}",
style: TextStyle(fontSize: 28.0),
),
),
],
),
],
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
),
),
onHorizontalDragEnd: (details) {
if (details.velocity.pixelsPerSecond.dx > 0) {
if (cardIndex > 0) cardIndex--;
} else {
if (cardIndex < 2) cardIndex++;
}
setState(() {
scrollController.animateTo((cardIndex) * 256.0,
duration: Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn);
});
},
onTap: () {
_launchURL("${videoList[position].url}");
});
},
),
);
}
else if (position == 3)
{
return Padding(
padding: EdgeInsets.all(16.0),
child: Text(
"Useful Links",
style: TextStyle(
fontSize: 36.0,
fontWeight: FontWeight.bold,
color: Colors.black),
),
);
}
else if (position == 4) //Links
{
//TODO PUT LINKS
}
},
);
}
}

前两个元素正确显示。我还在其他环境中尝试了 position == 2 中的元素,但在 listview.builder 之外并且工作正常。关于为什么它不显示的任何想法?谢谢。

最佳答案

您没有返回 Widget if(position == 2)

if (position == 2) {
//Add Return Statement HERE:
return Container(
height: 350.0,
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: 3,
controller: scrollController,
scrollDirection: Axis.horizontal,
itemBuilder: (context, position) {
return GestureDetector(
// All other stuff
);

},
),
);
}

关于listview - Flutter:ListView.builder 中的 ListView.builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54432248/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com