📅  最后修改于: 2022-03-11 14:59:37.478000             🧑  作者: Mango
import 'package:flutter/material.dart';
//Shohel Rana Shanto
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({ Key? key }) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length:4 ,
child: Scaffold(
backgroundColor: Colors.white10,
body: NestedScrollView(headerSliverBuilder: (context,_){
return [
SliverAppBar(
leading: Icon(Icons.menu),
actions: [
Icon(Icons.notifications),
Icon(Icons.search)
],
title: Text(' Sliver Persistent Header'),
backgroundColor: Colors.black87,
),
SliverPersistentHeader(
pinned: true, floating: true,
delegate: MyTab())
];
},
body: TabBarView(children: [
Container(color: Colors.green,child: GridView.count(crossAxisCount: 3,
children:
List.generate(100, (index) =>
Card(color:index%4==0?Colors.red:index%4==2?Colors.pink:index%4==1?Colors.yellow:Colors.blue,child: Text('Grid$index'),)
)
),),
Container(color: Colors.red,child: ListView.builder(
itemCount: 6,
itemBuilder: (context,index){
return Card(
child: ListTile(
title: Text('List$index'),
),
);
}),),
Container(color: Colors.yellow,),
Container(color: Colors.blue,),
]),
),
),
);
}
}
class MyTab extends SliverPersistentHeaderDelegate{
@override
Widget build(BuildContext context,double,bool) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.black,Colors.blue,Colors.black])
),
child: TabBar(
tabs: [
Tab(text: 'Grid',height:100,),
Tab(text: 'List',),
Tab(text: 'Manush',),
Tab(text: 'Shoytan',),
]),
);
}
@override
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
return true;
}
@override
double maxExtent = 110;
@override
double minExtent = 50;
}