Search
 
SCRIPT & CODE EXAMPLE
 

DART

sliver persistent header

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<HomePage> {
  @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;
}
Comment

PREVIOUS NEXT
Code Example
Dart :: flutter alert dialog shape 
Dart :: convert string date to datetime and format 
Dart :: radius only top or bottom flutter 
Dart :: get user country automatically flutter 
Dart :: list in dart 
Dart :: dart list generate 
Dart :: dart array split 
Dart :: dart list add 
Dart :: flutter icon color 
Dart :: Main function for flutter 
Dart :: flutter inheritance 
Dart :: Determine the Screen size using the MediaQuery class Flutter 
Dart :: create a int list dart 
Dart :: show snackbar flutter 
Dart :: get single element from list in dart 
Dart :: onetime onboarding flutter 
Dart :: flutter radio button 
Dart :: add all items to a list in dart 
Dart :: dart define value null 
Dart :: how to store special characters in dart string 
Dart :: access blocprovider inside a dispose method in flutter 
Dart :: flutter map get value by key 
Dart :: how to mesure execution time of method in dart 
Dart :: flutter check variable has object 
Dart :: desing patters para Flutter 
Dart :: inkwell not splashing in stack 
Swift :: add shadow to collection view cell swift 
Swift :: swift change navigation bar color 
Swift :: add toggle without text swiftui 
Swift :: swift navigation bar title font 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =