Search
 
SCRIPT & CODE EXAMPLE
 

DART

flutter 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 :: string to int in dart 
Dart :: Failed to load network image fliutter 
Dart :: timer.delay flutter 
Dart :: textbutton flutter 
Dart :: flutter showSnackBar replacme 
Dart :: flutter print http response 
Dart :: const vs final flutter 
Dart :: how to refresh a listview in flutter 
Dart :: flutter array filter 
Dart :: int.parse flutter 
Dart :: map in dart 
Dart :: flutter iterate over list widget 
Dart :: Error: java.io.IOException: No such file or directory in android 11 
Dart :: onpressed pass context flutter 
Dart :: flutter run ios white screen 
Dart :: timer class in flutter 
Dart :: how to avoid special characters in validator 
Dart :: Avoid `print` calls in production code 
Dart :: dart call nullable function 
Dart :: with keyword in dart 
Dart :: install fvm in flutter using pub package 
Dart :: crossaxisalignment.stretch row in column flutter 
Dart :: flutter constructors keep properties private with constructor 
Dart :: flutter: unhandled element defs; Picture key: AssetBundlePictureKey 
Dart :: Remove space between widgets in row flutter 
Dart :: dart print multiply 
Swift :: on swipe get contentoffset swift collectionview 
Swift :: swift uitableview cell spacing 
Swift :: swift animate a label ishidden 
Swift :: check when webview finish loading swift 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =