我试图做一个滚动屏幕,我可以有每个不同的图像垂直与一些功能,如星星评定栏,也许几个按钮。我首先尝试插入一张照片到滚动屏幕。这里是我的代码:'
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight:250,
pinned: true,
floating: true,
flexibleSpace: FlexibleSpaceBar(
background: Container(
padding: EdgeInsets.symmetric(horizontal: AppLayout.getWidth(20)),
child: Column(
children: [
Gap(AppLayout.getHeight(20)),
Row( // text
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"review", style: Styles.headLineStyle1,
),
],
)
],
),
Gap(AppLayout.getHeight(25)),
Container( //search bar
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(AppLayout.getHeight(10)),
color: const Color(0xFFF4F6FD)
),
padding: EdgeInsets.symmetric(horizontal: AppLayout.getWidth(12), vertical: AppLayout.getHeight(12)),
child: Row(
children: [
const Icon(FluentSystemIcons.ic_fluent_search_regular, color: Color(0xFFBFC205)),
Text(
"place, restaurant",
style: Styles.headLineStyle4,
)
],
),
),
],
),
),
),
),
'
出现错误的代码:
'
SliverList(
delegate: SliverChildListDelegate(
(BuildContext context, int index) {
return _buildListItem(foodList2[index]);
},
),
),
'
foodList2列表:
'
static const List<Tuple4> foodList2 = [
Tuple4<String, String, String, String> (
'assets/images/eel.jpg',
'assets/images/aburasoba.jpg',
'assets/images/soba.jpg',
'assets/images/okonomiyaki.jpg',
)
];
'
我试着查找关于SliverList的信息和更多关于SliverChildListDelegate的信息,我发现当我删除主体时,这个错误会消失。我确实想保留这个主体,所以有什么方法可以解决这个问题吗?(我知道我的代码中现在没有_buildListItem)
1条答案
按热度按时间km0tfn4u1#
如果要使用生成器方法,则需要使用
SliverChildBuilderDelegate
而不是SliverChildListDelegate
。还要记住,您的
_buildListItem
需要返回一个Widget