Last active
August 31, 2021 11:49
-
-
Save setbap/efe359d36f1fbde5f3c02836c6336432 to your computer and use it in GitHub Desktop.
flutter tabBar example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
const height = 80.0; | |
const gradientBreakPoint = .9; | |
const tabBarLen = 10; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: DefaultTabController( | |
length: tabBarLen, | |
initialIndex: 1, | |
child: Column( | |
children: [ | |
Container( | |
color: Colors.green, | |
height: height, | |
child: SingleChildScrollView( | |
child: TabBar( | |
labelColor: Colors.white, | |
physics: const BouncingScrollPhysics(), | |
unselectedLabelColor: Colors.black, | |
indicatorSize: TabBarIndicatorSize.tab, | |
isScrollable: true, | |
indicator: const BoxDecoration( | |
gradient: LinearGradient( | |
colors: [ | |
Colors.transparent, | |
Colors.transparent, | |
Colors.white, | |
Colors.white, | |
], | |
begin: Alignment.topCenter, | |
end: Alignment.bottomCenter, | |
stops: [ | |
0, | |
gradientBreakPoint, | |
gradientBreakPoint, | |
height | |
], | |
), | |
), | |
tabs: List.generate( | |
tabBarLen, | |
(index) => SizedBox( | |
height: height, | |
child: Center(child: Text("hm" + "m" * (index))), | |
), | |
), | |
), | |
), | |
), | |
Expanded( | |
child: TabBarView( | |
children: List.generate( | |
tabBarLen, | |
(index) => Center(child: Text(index.toString())), | |
)), | |
) | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment