Skip to content

Instantly share code, notes, and snippets.

@shihaohong
Created April 6, 2019 21:50
Show Gist options
  • Save shihaohong/4e0864b55d7482c7f080fe81047bcdec to your computer and use it in GitHub Desktop.
Save shihaohong/4e0864b55d7482c7f080fe81047bcdec to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TabBarTest(title: 'Test Tab Bar'),
);
}
}
class TabBarTest extends StatefulWidget {
TabBarTest({Key key, this.title}) : super(key: key);
final String title;
@override
_TabBarTestState createState() => _TabBarTestState();
}
class _TabBarTestState extends State<TabBarTest> with TickerProviderStateMixin {
TabController _tabController;
List<Widget> _tabs = [
Container(decoration: BoxDecoration(color: Colors.red)),
Container(decoration: BoxDecoration(color: Colors.blue)),
Container(decoration: BoxDecoration(color: Colors.greenAccent)),
];
@override
void initState() {
_tabController = TabController(vsync: this, length: 3);
super.initState();
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('tabBarTesting')),
body: TabBarView(children: _tabs, controller: _tabController),
bottomNavigationBar: TabBar(controller: _tabController, tabs: const <Tab>[
Tab(icon: Icon(Icons.person), text: 'Home'),
Tab(icon: Icon(Icons.school), text: 'Grades'),
Tab(icon: Icon(Icons.settings), text: 'Settings')
]),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment