main.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import './tabs/home.dart' as _firstTab;
  4. import './tabs/dashboard.dart' as _secondTab;
  5. import './tabs/settings.dart' as _thirdTab;
  6. import './screens/about.dart' as _aboutPage;
  7. import './screens/support.dart' as _supportPage;
  8. void main() => runApp(new MaterialApp(
  9. title: 'Flutter Starter',
  10. theme: new ThemeData(
  11. primarySwatch: Colors.blueGrey,
  12. scaffoldBackgroundColor: Colors.white,
  13. primaryColor: Colors.blueGrey, backgroundColor: Colors.white
  14. ),
  15. home: new Tabs(),
  16. onGenerateRoute: (RouteSettings settings) {
  17. switch (settings.name) {
  18. case '/about': return new FromRightToLeft(
  19. builder: (_) => new _aboutPage.About(),
  20. settings: settings,
  21. );
  22. case '/support': return new FromRightToLeft(
  23. builder: (_) => new _supportPage.Support(),
  24. settings: settings,
  25. );
  26. }
  27. },
  28. // routes: <String, WidgetBuilder> {
  29. // '/about': (BuildContext context) => new _aboutPage.About(),
  30. // }
  31. ));
  32. class FromRightToLeft<T> extends MaterialPageRoute<T> {
  33. FromRightToLeft({ WidgetBuilder builder, RouteSettings settings })
  34. : super(builder: builder, settings: settings);
  35. @override
  36. Widget buildTransitions(
  37. BuildContext context,
  38. Animation<double> animation,
  39. Animation<double> secondaryAnimation,
  40. Widget child) {
  41. if (settings.isInitialRoute)
  42. return child;
  43. return new SlideTransition(
  44. child: new Container(
  45. decoration: new BoxDecoration(
  46. boxShadow: [
  47. new BoxShadow(
  48. color: Colors.black26,
  49. blurRadius: 25.0,
  50. )
  51. ]
  52. ),
  53. child: child,
  54. ),
  55. position: new FractionalOffsetTween(
  56. begin: const FractionalOffset(1.0, 0.0),
  57. end: FractionalOffset.topLeft,
  58. )
  59. .animate(
  60. new CurvedAnimation(
  61. parent: animation,
  62. curve: Curves.fastOutSlowIn,
  63. )
  64. ),
  65. );
  66. }
  67. @override Duration get transitionDuration => const Duration(milliseconds: 400);
  68. }
  69. class Tabs extends StatefulWidget {
  70. @override
  71. TabsState createState() => new TabsState();
  72. }
  73. class TabsState extends State<Tabs> {
  74. PageController _tabController;
  75. var _title_app = null;
  76. int _tab = 0;
  77. @override
  78. void initState() {
  79. super.initState();
  80. _tabController = new PageController();
  81. this._title_app = TabItems[0].title;
  82. }
  83. @override
  84. void dispose(){
  85. super.dispose();
  86. _tabController.dispose();
  87. }
  88. @override
  89. Widget build (BuildContext context) => new Scaffold(
  90. //App Bar
  91. appBar: new AppBar(
  92. title: new Text(
  93. _title_app,
  94. style: new TextStyle(
  95. fontSize: Theme.of(context).platform == TargetPlatform.iOS ? 17.0 : 20.0,
  96. ),
  97. ),
  98. elevation: Theme.of(context).platform == TargetPlatform.iOS ? 0.0 : 4.0,
  99. ),
  100. //Content of tabs
  101. body: new PageView(
  102. controller: _tabController,
  103. onPageChanged: onTabChanged,
  104. children: <Widget>[
  105. new _firstTab.Home(),
  106. new _secondTab.Dashboard(),
  107. new _thirdTab.Settings()
  108. ],
  109. ),
  110. //Tabs
  111. bottomNavigationBar: Theme.of(context).platform == TargetPlatform.iOS ?
  112. new CupertinoTabBar(
  113. activeColor: Colors.blueGrey,
  114. currentIndex: _tab,
  115. onTap: onTap,
  116. items: TabItems.map((TabItem) {
  117. return new BottomNavigationBarItem(
  118. title: new Text(TabItem.title),
  119. icon: new Icon(TabItem.icon),
  120. );
  121. }).toList(),
  122. ):
  123. new BottomNavigationBar(
  124. currentIndex: _tab,
  125. onTap: onTap,
  126. items: TabItems.map((TabItem) {
  127. return new BottomNavigationBarItem(
  128. title: new Text(TabItem.title),
  129. icon: new Icon(TabItem.icon),
  130. );
  131. }).toList(),
  132. ),
  133. //Drawer
  134. drawer: new Drawer(
  135. child: new ListView(
  136. children: <Widget>[
  137. new Container(
  138. height: 120.0,
  139. child: new DrawerHeader(
  140. padding: new EdgeInsets.all(0.0),
  141. decoration: new BoxDecoration(
  142. color: new Color(0xFFECEFF1),
  143. ),
  144. child: new Center(
  145. child: new FlutterLogo(
  146. colors: Colors.blueGrey,
  147. size: 54.0,
  148. ),
  149. ),
  150. ),
  151. ),
  152. new ListTile(
  153. leading: new Icon(Icons.chat),
  154. title: new Text('Support'),
  155. onTap: () {
  156. Navigator.pop(context);
  157. Navigator.of(context).pushNamed('/support');
  158. }
  159. ),
  160. new ListTile(
  161. leading: new Icon(Icons.info),
  162. title: new Text('About'),
  163. onTap: () {
  164. Navigator.pop(context);
  165. Navigator.of(context).pushNamed('/about');
  166. }
  167. ),
  168. new Divider(),
  169. new ListTile(
  170. leading: new Icon(Icons.exit_to_app),
  171. title: new Text('Sign Out'),
  172. onTap: () {
  173. Navigator.pop(context);
  174. }
  175. ),
  176. ],
  177. )
  178. )
  179. );
  180. void onTap(int tab){
  181. _tabController.jumpToPage(tab);
  182. }
  183. void onTabChanged(int tab) {
  184. setState((){
  185. this._tab = tab;
  186. });
  187. switch (tab) {
  188. case 0:
  189. this._title_app = TabItems[0].title;
  190. break;
  191. case 1:
  192. this._title_app = TabItems[1].title;
  193. break;
  194. case 2:
  195. this._title_app = TabItems[2].title;
  196. break;
  197. }
  198. }
  199. }
  200. class TabItem {
  201. const TabItem({ this.title, this.icon });
  202. final String title;
  203. final IconData icon;
  204. }
  205. const List<TabItem> TabItems = const <TabItem>[
  206. const TabItem(title: 'Home', icon: Icons.home),
  207. const TabItem(title: 'Dashboard', icon: Icons.dashboard),
  208. const TabItem(title: 'Settings', icon: Icons.settings)
  209. ];