📜  flutter sliver TabBar - Dart 代码示例

📅  最后修改于: 2022-03-11 14:48:09.127000             🧑  作者: Mango

代码示例1
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(
        body: NestedScrollView(headerSliverBuilder: (context,_){
          return [
            SliverAppBar(
              pinned: true,
              title: Text('Sliver TabBar'),
              backgroundColor: Colors.black87,
              bottom: TabBar(tabs: [
                Tab(text: 'Grid',),
                Tab(text: 'List',),
                Tab(text: 'Images',),
                Tab(text: 'Color',),
              ]),
            )
          ];
        },
        
         body: TabBarView(children: [
           Container(color: Colors.green,child: GridView.count(crossAxisCount: 3,
           children: 
             List.generate(100, (index) => 
             Card(color: Colors.amber,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,),
         ]),
      
      ),
      ),
    );
  }
}