SliverPadding
的工作方式与普通Padding
小部件的工作方式相同。唯一的区别是它需要sliver
而不是child
。总的来说SliverPadding
组件是sliver
系列的Padding
组件。
构造函数:
const SliverPadding({
super.key,
required this.padding,
Widget? sliver,
})
例子:
import 'package:flutter/material.dart';
class SliverPaddingPage extends StatelessWidget {
const SliverPaddingPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('SliverPadding'),),
body: CustomScrollView(
slivers: [
SliverPadding(
padding: const EdgeInsets.all(20),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(context,index){
return Container(
height: 50,
alignment: Alignment.center,
color: Colors.primaries[index % Colors.primaries.length],
child: Text('List item : $index'),
);
},
childCount: 10
),
),
)
],
),
);
}
}