import 'package:flutter/material.dart'; import 'package:progress_indicators/progress_indicators.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:teso/Classes/Uploading.dart'; import 'package:teso/Pages/Sub_Pages/homeSub/MyCoupons.dart'; import 'package:teso/Pages/Sub_Pages/homeSub/HomeFeed.dart'; import 'package:teso/providers/pageAnimations.dart'; import 'package:teso/util/consts.dart'; import 'Sub_Pages/CoinPurchase.dart'; import 'package:teso/providers/user_provider.dart'; import 'package:provider/provider.dart'; import 'Sub_Pages/homeSub/ProximityCoupons.dart'; import 'firsttimer.dart'; class Home extends StatefulWidget { final Function showUploads; final Function toggle; const Home({Key key, this.showUploads, this.toggle}) : super(key: key); @override _HomeState createState() => _HomeState(showUploads: this.showUploads); } class _HomeState extends State with TickerProviderStateMixin { Function showUploads; _HomeState({this.showUploads}); TabController tabsController; String title = "Home"; double titleSize = 45.0; @override void initState() { super.initState(); tabsController = new TabController(length: 3, initialIndex: 1, vsync: this); tabsController.addListener(() { if (tabsController.index == 1) { setState(() { title = "Home"; titleSize = 45.0; }); widget.toggle(true); } else if (tabsController.index == 2) { setState(() { title = "Proximity Coupons"; titleSize = 30.0; }); widget.toggle(false); } else { setState(() { title = "Coupons"; titleSize = 45.0; }); widget.toggle(true); } }); SharedPreferences.getInstance().then((prefs) async { bool first = prefs.getBool("launched") != null ? prefs.getBool("launched") : false; if (!first) { int result = await Navigator.push( context, PageTransition( type: PageTransitionType.fade, child: FirstTimeIntro(), )); prefs.setBool("launched", true); tabsController.animateTo(result); } }); } @override void dispose() { super.dispose(); tabsController.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: buildAppBar(context), body: TabBarView( controller: tabsController, children: [ MyCoupons(), HomeFeed(), ProximityCoupons(), ], ), ); } Widget buildAppBar(BuildContext context) { return PreferredSize( child: Material( //elevation: 0.4, child: AppBar( backgroundColor: Theme.of(context).primaryColor, automaticallyImplyLeading: false, title: Consumer(builder: (BuildContext context, UserProvider value, Widget child) { List provider = value.getPending(); return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( title, style: TextStyle( color: Theme.of(context).primaryColorLight, fontFamily: 'DeadheadScript', fontSize: titleSize, letterSpacing: 3.0, ), ), Container( height: 30, child: Row( children: [ provider == null || provider.length == 0 ? Container() : GestureDetector( onTap: () => showUploads(context), child: Container( height: 40, width: 40, margin: EdgeInsets.only(right: 15), child: HeartbeatProgressIndicator( child: Icon( Icons.upload, color: tesoBlue, size: 18, ), ), ), ), GestureDetector( onTap: () => Navigator.push( context, PageTransition( type: PageTransitionType.downToUp, child: Coins( initalPage: 0, ), ), ), child: Image( image: AssetImage("assets/images/gold1.png"), ), ), GestureDetector( onTap: () => Navigator.push( context, PageTransition( type: PageTransitionType.downToUp, child: Coins(initalPage: 0), ), ), child: Container( margin: EdgeInsets.only(left: 2), child: Center( child: Text( value.currentUser != null ? value.currentUser.gold : "0", style: TextStyle( fontSize: 13.5, color: Theme.of(context).primaryColorLight, ), ), ), ), ), GestureDetector( onTap: () => Navigator.push( context, PageTransition( type: PageTransitionType.downToUp, child: Coins(initalPage: 1), ), ), child: Image( image: AssetImage("assets/images/silver1.png"), ), ), GestureDetector( onTap: () => Navigator.push( context, PageTransition( type: PageTransitionType.downToUp, child: Coins(initalPage: 1), ), ), child: Container( margin: EdgeInsets.only(left: 2), child: Center( child: Text( value.currentUser != null ? value.currentUser.silver : "0", style: TextStyle( fontSize: 13.5, color: Theme.of(context).primaryColorLight, ), ), ), ), ), ], ), ), ], ); }), ), ), preferredSize: Size.fromHeight(50.0)); } }