Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primaryColor: Color(0xFF0f1e3d),
- // brightness: Brightness.dark
- ),
- debugShowCheckedModeBanner: false,
- home: MyTabbedPage(),
- );
- }
- }
- class MyTabbedPage extends StatefulWidget {
- const MyTabbedPage({Key key}) : super(key: key);
- @override
- _MyTabbedPageState createState() => new _MyTabbedPageState();
- }
- class _MyTabbedPageState extends State<MyTabbedPage>
- with SingleTickerProviderStateMixin {
- TabController _tabController;
- @override
- void initState() {
- super.initState();
- _tabController = new TabController(vsync: this, length: 2);
- _tabController.addListener(_handleTabChange);
- }
- @override
- void dispose() {
- _tabController.dispose();
- super.dispose();
- }
- void _handleTabChange() {
- setState(() {
- print("touched");
- index = _tabController.index;
- print(index);
- });
- }
- int index;
- @override
- Widget build(BuildContext context) {
- print(_tabController.index);
- return new Scaffold(
- appBar: new AppBar(
- bottom: new TabBar(
- controller: _tabController,
- onTap: (int i) {
- setState(() {
- print("touched");
- index = i;
- print(index);
- });
- },
- tabs: <Tab>[
- new Tab(
- text: index == 0 ? 'LEFT' : null,
- icon: index == 0 ? null : Icon(Icons.mail),
- ),
- new Tab(
- text: index == 1 ? 'RIGHT' : null,
- icon: index == 1 ? null : Icon(Icons.adb),
- ),
- ],
- ),
- ),
- body: new TabBarView(controller: _tabController, children: [
- Text("left"),
- Text("right"),
- ]),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement