import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SliverListDemo extends StatefulWidget{
@override
_SliverListDemoState createState()=>_SliverListDemoState();
}
class _SliverListDemoState extends State<SliverListDemo>{
@override
void initState() {
// TODO: implement initState
super.initState();
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("SliverList简单样例"),
),
body: CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildListDelegate([
Container(
height: 80,
color: Colors.primaries[0],
child: Text('SliverChildListDelegate_0'),
),
Container(
height: 80,
color: Colors.primaries[1],
child: Text('SliverChildListDelegate_1'),
),
Container(
height: 80,
color: Colors.primaries[2],
child: Text('SliverChildListDelegate_2'),
),
Container(
height: 80,
color: Colors.primaries[3],
child: Text('SliverChildListDelegate_3'),
),
Container(
height: 80,
color: Colors.primaries[4],
child: Text('SliverChildListDelegate_4'),
),
]),
),
SliverList(
delegate: SliverChildBuilderDelegate((content, index) {
return Container(
height: 65,
color: Colors.primaries[index % Colors.primaries.length],
child: Text('SliverChildBuilderDelegate_$index'),
);
},
//行数
childCount: 20,
//是否保存行的状态,默认是true
addAutomaticKeepAlives:true,
),
),
],
),
);
}
}
转自:https://blog.csdn.net/weixin_46642112/article/details/116301154