Created
December 28, 2019 15:19
-
-
Save akshatapp/6c4d730328bac4a4d2abacdbd61476cc to your computer and use it in GitHub Desktop.
Flutter Tabs Demo
This file contains 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
// To learn more visit - https://www.akshatapp.com/tutorials/flutter-tutorial | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Flutter Tabs Demo', | |
theme: ThemeData(primarySwatch: Colors.purple), | |
home: MyHomePage(), | |
); | |
} | |
} | |
// Page 1 - Create Product | |
class CreateTabPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Center( | |
child: Icon( | |
Icons.edit, | |
color: Color(0xFFD50000), | |
), | |
), | |
); | |
} | |
} | |
// Page 2 - Manage Products | |
class ManageTabPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Center( | |
child: Icon( | |
Icons.view_list, | |
color: Colors.pink, | |
), | |
), | |
); | |
} | |
} | |
// Page 3 - Product Info | |
class InfoTabPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Center( | |
child: Icon( | |
Icons.info, | |
color: Colors.blue, | |
), | |
), | |
); | |
} | |
} | |
//DefaultTabController Example | |
class MyHomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return DefaultTabController( | |
length: 3, | |
child: Scaffold( | |
appBar: AppBar( | |
title: Text('Flutter Tabs Demo'), | |
bottom: TabBar( | |
tabs: <Widget>[ | |
Tab(icon: Icon(Icons.edit), text: "Create Product"), | |
Tab(icon: Icon(Icons.view_list), text: "Manage Product"), | |
Tab(icon: Icon(Icons.info), text: "Product Info") | |
], | |
), | |
), | |
body: TabBarView( | |
children: <Widget>[CreateTabPage(), ManageTabPage(), InfoTabPage()], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment