Skip to content

Instantly share code, notes, and snippets.

@ericguzman
Created March 27, 2020 04:12
Show Gist options
  • Save ericguzman/7c48f7a80b3d81e56d65c7b719d2889b to your computer and use it in GitHub Desktop.
Save ericguzman/7c48f7a80b3d81e56d65c7b719d2889b to your computer and use it in GitHub Desktop.
TabBar Demo
import 'package:flutter/material.dart';
final Color black = Color.fromARGB(255, 0, 0, 0);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: black),
debugShowCheckedModeBanner: false,
home: MyTabbedPage(),
);
}
}
class MyTabbedPage extends StatefulWidget {
const MyTabbedPage({ Key key }) : super(key: key);
@override
_MyTabbedPageState createState() => _MyTabbedPageState();
}
class _MyTabbedPageState extends State<MyTabbedPage> with SingleTickerProviderStateMixin {
final List<Tab> myTabs = <Tab>[
Tab(text: 'LEFT'),
Tab(text: 'RIGHT'),
Tab(text: 'TOP'),
Tab(text: 'BOTTOM'),
Tab(text: 'CENTER'),
Tab(text: 'TOP_RIGHT'),
Tab(text: 'TOP_LEFT'),
Tab(text: 'BOTTOM_RIGHT'),
Tab(text: 'BOTTOM_LEFT'),
];
TabController _tabController;
@override
void initState() {
super.initState();
_tabController = TabController(vsync: this, length: myTabs.length);
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
bottom: TabBar(
isScrollable: true,
indicatorColor: Colors.transparent,
controller: _tabController,
tabs: myTabs,
),
),
body: TabBarView(
controller: _tabController,
children: myTabs.map((Tab tab) {
final String label = tab.text.toLowerCase();
return Center(
child: Text(
'This is the $label tab',
style: const TextStyle(fontSize: 36),
),
);
}).toList(),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment