Skip to content

Instantly share code, notes, and snippets.

@setbap
Last active August 31, 2021 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save setbap/efe359d36f1fbde5f3c02836c6336432 to your computer and use it in GitHub Desktop.
Save setbap/efe359d36f1fbde5f3c02836c6336432 to your computer and use it in GitHub Desktop.
flutter tabBar example
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