flutter - 将容器添加到 Sliver
问题描述
我刚开始学习 slivers,它们似乎不适用于任何其他 Flutter 小部件,除了以“Sliver”开头的小部件。我尝试添加一个Container
,这样我就可以添加BorderRadius
来装饰列表。但我得到了这个错误:
RenderSliverFillRemaining 需要 RenderBox 类型的子代,但收到了 RenderSliverToBoxAdapter 类型的子代。
到目前为止,这是我的代码:
...
SliverFillRemaining(
child: SliverToBoxAdapter(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(36),
topRight: Radius.circular(36),
),
),
child: SliverPadding(
padding: const EdgeInsets.all(16),
sliver: 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'),
);
},
),
),
),
),
),
),
...
解决方案
我通过使用 aNestedScrollView
而不是 a解决了我的问题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'),
);
},
),
),
),
);
推荐阅读
- python - 使用 qt v=5.9.0 创建 conda env
- docker - 如何在 docker compose 3.7 中指定最大 cpu 和 ram
- android - GridLayout 中的 TextViews 在 Android 右侧被截断
- kubernetes - 我想为前端部署一个部署 1 个 pod,为后端部署一个具有持久卷的 pod
- sql - 将包含 20.000 个字符的字符串存储到 SQL 中的变量中
- git - 从 git diff 中找出更改的行号
- android - Kotlin,类型不匹配所需的布尔找到类
*问题本身已修复* - amazon-web-services - EC2 启动和停止自动化
- python - 对于这个具有随机初始化权重的未经训练的神经网络,所有输入(或多或少)给出相同的输出
- bash - 使用 bash、Azure CLI 和 REST API 访问 CosmosDB - 如何正确获取令牌和哈希?