SliverFillViewport
生成的每一个child
都占满全屏。使用场景PageView
。构造函数
const SliverFillViewport({
super.key,
required this.delegate,
this.viewportFraction = 1.0,//是否占满全屏
this.padEnds = true,
})
例子:
import 'package:flutter/material.dart';
class SliverFillViewportPage extends StatelessWidget {
const SliverFillViewportPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: [
SliverFillViewport(
delegate: SliverChildBuilderDelegate((context,index){
return Container(
color: Colors.primaries[index % Colors.primaries.length],
);
},childCount: 5),
viewportFraction: 1.0,
)
],
),
);
}
}