我刚刚开始学习银条,除了以“银条”开头的小部件外,它们似乎无法与其他Flutter小部件一起使用。我尝试添加Object
,以便可以添加Container
装饰列表。但是我遇到了这个错误:
RenderSliverFillRemaining预期为RenderBox类型的子代,但 收到了一个RenderSliverToBoxAdapter类型的孩子。
到目前为止,这是我的代码:
BorderRadius
答案 0 :(得分:1)
[更新] 根据您的用例,我认为您甚至不需要SliverFillRemaining,如果您希望SliverFillRemaining内部的列表是无限的,只需将SliverList与SliverChildBuilderDelegate一起使用
...
SliverFixedExtentList(
itemExtent: 50.0,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.lightBlue[100 * (index % 9)],
child: Text('List Item $index'),
);
},
),
),
...
上一个
您已经在错误中找到答案了,您SliverFillRemaining不使用银色,它使用的应该是小部件的孩子
...
SliverFillRemaining(
hasScrollBody: true,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(36),
topRight: Radius.circular(36),
),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: ListView.builder(
itemCount: 20,
physics: NeverScrollableScrollPhysics(), //adding this line will disable the scrolling and listview and so the CustomScrollView should work as a single scroll view
itemBuilder: (_, __) => ListTile(
title: Text("Item"),
),
),
),
),
),
...
答案 1 :(得分:0)
我通过使用NestedScrollView
而不是CustomScrollView
解决了我的问题。
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
floating: false,
pinned: true,
snap: false,
elevation: 0,
expandedHeight: 150.0,
brightness: DynamicTheme.of(context).brightness,
flexibleSpace: FlexibleSpaceBar(
title: Text(assignment.name),
),
),
];
},
body: Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(36),
topRight: Radius.circular(36),
),
),
child: ListView.builder(
itemExtent: 50.0,
itemBuilder: (context, index) {
return Container(
alignment: Alignment.center,
color: Colors.lightBlue[100 * (index % 9)],
child: Text('List Item $index'),
);
},
),
),
),
);