import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:provider/provider.dart'; import 'package:teso/Classes/API%20Clasess/CouponHead.dart'; import 'package:teso/Classes/CouponRateCalculator.dart'; import 'package:teso/Pages/Sub_Pages/@Generic/ProductImage.dart'; import 'package:teso/providers/device_provider.dart'; import 'package:teso/util/consts.dart'; import 'package:teso/Classes/API Clasess/CouponDetails.dart'; class ProductView extends StatefulWidget { final CouponDetails couponDetails; const ProductView({Key key, this.couponDetails}) : super(key: key); @override _ProductViewState createState() => _ProductViewState(); } enum AppBarBehavior { normal, pinned, floating, snapping } class _ProductViewState extends State with TickerProviderStateMixin { AnimationController _containerController; Animation width; Animation heigth; double _appBarHeight = 256.0; AppBarBehavior _appBarBehavior = AppBarBehavior.pinned; int number = 0; bool acquiring = false; void acceptCoupon() { setState(() { acquiring = true; }); CouponsHead couponsHead = new CouponsHead(); couponsHead.businessId = widget.couponDetails.businessId; couponsHead.expiration = widget.couponDetails.expiration; couponsHead.couponId = widget.couponDetails.couponId; couponsHead.quantity = 1; couponsHead.state = "active"; couponsHead.lower = double.parse(widget.couponDetails.lowerLimit.toString()); couponsHead.upper = double.parse(widget.couponDetails.upperLimit.toString()); couponsHead.targetProduct = widget.couponDetails.targetProduct.productID; double price = (widget.couponDetails.targetProduct.unitPrice * (widget.couponDetails.lowerLimit / 100)); //Calculations int cost = CouponRateCalculator.getRate(price); Provider.of(context, listen: false) .acceptCoupon(couponsHead, cost.ceil(), context); setState(() { acquiring = false; }); } void redeemCoupon() { setState(() { acquiring = true; }); //Calculations // int cost = CouponRateCalculator.getRate(price); // Provider.of(context, listen: false) // .acceptCoupon(couponsHead, cost.ceil(), context); setState(() { acquiring = false; }); } @override void initState() { _containerController = new AnimationController( duration: new Duration(milliseconds: 2000), vsync: this); super.initState(); width = new Tween( begin: 200.0, end: 220.0, ).animate( new CurvedAnimation( parent: _containerController, curve: Curves.ease, ), ); heigth = new Tween( begin: 400.0, end: 400.0, ).animate( new CurvedAnimation( parent: _containerController, curve: Curves.ease, ), ); heigth.addListener(() { setState(() { if (heigth.isCompleted) {} }); }); _containerController.forward(); } @override void dispose() { _containerController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { // timeDilation = 0.7; return new Theme( data: new ThemeData( brightness: Brightness.light, platform: Theme.of(context).platform, ), child: new Container( width: width.value, height: heigth.value, child: new Card( color: Colors.transparent, child: new Container( alignment: Alignment.center, width: width.value, height: heigth.value, decoration: new BoxDecoration( color: Colors.white, borderRadius: new BorderRadius.circular(10.0), ), child: new Stack( alignment: AlignmentDirectional.bottomCenter, children: [ new CustomScrollView( shrinkWrap: false, slivers: [ new SliverAppBar( elevation: 0.0, forceElevated: true, leading: new IconButton( onPressed: () { Navigator.of(context).pop(); }, icon: Container( width: 40, height: 40, decoration: BoxDecoration( shape: BoxShape.circle, color: Color.fromRGBO(0, 0, 0, 0.4), ), child: new Icon( Icons.arrow_back, color: Colors.white, size: 25.0, ), ), ), expandedHeight: _appBarHeight, pinned: _appBarBehavior == AppBarBehavior.pinned, floating: _appBarBehavior == AppBarBehavior.floating || _appBarBehavior == AppBarBehavior.snapping, snap: _appBarBehavior == AppBarBehavior.snapping, backgroundColor: Theme.of(context).backgroundColor, flexibleSpace: new FlexibleSpaceBar( background: new Stack( fit: StackFit.expand, children: [ GestureDetector( onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) { return ProductImage( productTag: widget .couponDetails.targetProduct.businessID, productImageSRC: widget.couponDetails .targetProduct.productImage, ); })); }, child: new Container( width: width.value, height: _appBarHeight, child: Hero( tag: widget .couponDetails.targetProduct.businessID, child: CachedNetworkImage( imageUrl: productURL + widget.couponDetails.targetProduct .productImage, imageBuilder: (context, imageProvider) => Image( fit: BoxFit.fill, image: imageProvider, ), ), ), ), ), ], ), ), ), new SliverList( delegate: new SliverChildListDelegate([ new Container( color: Colors.white, child: new Padding( padding: const EdgeInsets.all(35.0), child: new Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ new Container( padding: new EdgeInsets.only(bottom: 20.0), alignment: Alignment.center, decoration: new BoxDecoration( color: Colors.white, border: new Border( bottom: new BorderSide( color: Colors.black12))), child: new Wrap( children: [ new Center( child: new Text( widget.couponDetails.targetProduct .productName, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 24, ), ), ), new Row( children: [ new Icon(Icons.shopping_bag), new Padding( padding: const EdgeInsets.all(8.0), child: new Text( "Price : ", style: TextStyle( fontWeight: FontWeight.bold, ), ), ), new Padding( padding: const EdgeInsets.all(8.0), child: new Text("GH¢ " + widget.couponDetails .targetProduct.unitPrice .toString()), ) ], ), SingleChildScrollView( scrollDirection: Axis.horizontal, child: new Row( children: [ new Icon( Icons.store, ), new Padding( padding: const EdgeInsets.all(8.0), child: new Text( "Shop Name : ", style: TextStyle( fontWeight: FontWeight.bold, ), ), ), new Padding( padding: const EdgeInsets.all(8.0), child: new Text(widget .couponDetails .issuer .businessName), ) ], ), ), ], ), ), new Padding( padding: const EdgeInsets.only( top: 16.0, bottom: 8.0), child: new Text( "Product Description", style: new TextStyle( fontWeight: FontWeight.bold), ), ), new Text(widget .couponDetails.targetProduct.productDesc), ], ), ), ), ]), ), ], ), widget.couponDetails.countID == "null" ? Container( height: 80.0, padding: EdgeInsets.all(20), child: new TextButton( onPressed: acceptCoupon, child: new Container( height: 50.0, alignment: Alignment.center, decoration: new BoxDecoration( color: tesoGold, borderRadius: new BorderRadius.circular(60.0), ), child: new Text( "Accept Coupon", style: new TextStyle(color: Colors.white), ), ), ), ) : Container( height: 80.0, padding: EdgeInsets.all(20), child: new TextButton( onPressed: () => print(""), child: new Container( height: 50.0, alignment: Alignment.center, decoration: new BoxDecoration( color: tesoGold, borderRadius: new BorderRadius.circular(60.0), ), child: new Text( "Redeem Coupon", style: new TextStyle(color: Colors.white), ), ), ), ), Visibility( visible: acquiring, child: Container( height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, color: Colors.transparent, child: Center( child: CupertinoActivityIndicator( animating: true, radius: 15, ), ), ), ), ], ), ), ), ), ); } }