import 'package:flutter/material.dart'; import 'package:teso/Classes/API Clasess/CouponDetails.dart'; import 'package:teso/Classes/CouponRateCalculator.dart'; import 'package:teso/util/SizeConfig.dart'; import 'package:teso/util/consts.dart'; import 'dart:math' as math; import 'package:teso/Classes/API Clasess/CouponHead.dart'; buildFreebieCoupon( BuildContext context, CouponDetails coupon, Function acquiring) { SizeConfig().init(context); return Container( width: SizeConfig.safeBlockHorizontal * 70, height: SizeConfig.safeBlockVertical * 85, margin: EdgeInsets.only( left: MediaQuery.of(context).size.width * 0.1, ), child: Column( children: [ Container( width: MediaQuery.of(context).size.width * 0.70, height: MediaQuery.of(context).size.height * 0.68, decoration: BoxDecoration( borderRadius: BorderRadius.only( bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20), topLeft: Radius.circular(20), topRight: Radius.circular(20), ), color: Colors.white, ), child: ClipRRect( borderRadius: BorderRadius.only( bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20), topLeft: Radius.circular(20), topRight: Radius.circular(20), ), child: Column( children: [ Container( width: MediaQuery.of(context).size.width * 0.70, height: MediaQuery.of(context).size.height * 0.55, padding: EdgeInsets.all(8.0), decoration: BoxDecoration( color: Colors.white, image: DecorationImage( fit: BoxFit.fill, image: AssetImage("assets/images/grey.png"), colorFilter: new ColorFilter.mode( tesoAsh.withOpacity(1.0), BlendMode.overlay), ), borderRadius: BorderRadius.only( bottomLeft: Radius.circular(80), bottomRight: Radius.circular(80), ), ), child: Stack( children: [ Align( alignment: Alignment.topLeft, child: Row( children: [ Image( width: 30, image: AssetImage( "assets/images/tesoCouponInsignia.png")), SizedBox( width: 5, ), Text( "TESO", style: TextStyle( color: Colors.black, fontSize: 15, ), ), ], ), ), Align( alignment: Alignment.topCenter, child: Container( margin: EdgeInsets.only( top: MediaQuery.of(context).size.width * 0.125, ), child: Column( children: [ Text( coupon.issuer.businessName.toUpperCase(), style: TextStyle( color: Colors.black, fontSize: 18, fontWeight: FontWeight.w700, ), ), Container( width: double.infinity, margin: EdgeInsets.symmetric( vertical: 10, ), child: Center( child: Text( "FREEBIE", textAlign: TextAlign.center, style: TextStyle( color: Colors.black, fontSize: 25, fontWeight: FontWeight.w900, ), ), ), ), ], ), ), ), Align( alignment: Alignment.center, child: Container( height: SizeConfig.safeBlockHorizontal * 16, padding: EdgeInsets.all(4.5), decoration: BoxDecoration( border: Border.all(color: Colors.black, width: 2), ), child: Center( child: Column( children: [ Text( "ORIGINAL PRICE : GH¢ " + coupon.targetProduct.unitPrice .toStringAsFixed(2), style: TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: SizeConfig.safeBlockHorizontal * 3, ), ), Text( "DISCOUNTED PRICE : GH¢ 0.00", style: TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: SizeConfig.safeBlockHorizontal * 3, ), ), new Wrap( direction: Axis.horizontal, children: [ Image( width: SizeConfig.safeBlockHorizontal * 5, image: AssetImage( "assets/images/silver1.png"), ), Container( margin: EdgeInsets.only( top: 5, ), child: Text( "SILVER COIN COST : ", style: TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: SizeConfig.safeBlockHorizontal * 3, ), ), ), Container( margin: EdgeInsets.only( top: 5, ), child: Text( CouponRateCalculator.getRate( coupon.targetProduct.unitPrice * (coupon.worth / 100)) .toString(), style: TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: SizeConfig.safeBlockHorizontal * 3, ), ), ), ], ), ], ), ), ), ), Align( alignment: Alignment.bottomCenter, child: Container( margin: EdgeInsets.symmetric( vertical: MediaQuery.of(context).size.width * 0.15), child: Text( coupon.targetProduct.productName.toUpperCase(), textAlign: TextAlign.center, style: TextStyle( color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold, ), ), ), ), ], ), ), Container( padding: EdgeInsets.symmetric( horizontal: MediaQuery.of(context).size.width * 0.025, ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( width: MediaQuery.of(context).size.width * 0.4, height: 70, padding: EdgeInsets.only( top: 5, ), child: SingleChildScrollView( scrollDirection: Axis.vertical, child: Column( children: [ Container( child: Text( "Pay : GH¢ 0.00 only", style: TextStyle( color: Colors.red, fontWeight: FontWeight.bold, ), ), ), coupon.condition == 'none' ? Container() : Container( child: Text( "Condition : " + coupon.condition .replaceAll('"', ""), style: TextStyle( color: Colors.black, ), ), ), ], ), ), ), Container( width: 70, height: 70, padding: EdgeInsets.all(2.5), decoration: BoxDecoration( border: Border.all( color: Colors.red, ), borderRadius: BorderRadius.only( topLeft: Radius.circular(80), topRight: Radius.circular(80), bottomLeft: Radius.circular(80), bottomRight: Radius.circular(80), ), ), child: Container( width: 70, height: 70, //padding: EdgeInsets.all(2.5), decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.red, border: Border.all(color: Colors.red), image: DecorationImage( fit: BoxFit.fill, image: AssetImage("assets/images/red.png"), colorFilter: new ColorFilter.mode( Colors.red.withOpacity(0.5), BlendMode.overlay), ), ), child: Transform.rotate( angle: -math.pi / 4, child: Container( margin: EdgeInsets.symmetric( vertical: 20, horizontal: 5), height: 10, child: Text( "FREE!!!", style: TextStyle( color: Colors.white, fontSize: 16.2, fontWeight: FontWeight.bold, ), ), ), ), ), ), ], ), ), ], ), ), ), Container( margin: EdgeInsets.symmetric( vertical: MediaQuery.of(context).size.width * 0.03, ), child: ElevatedButton( style: ElevatedButton.styleFrom( primary: accentMain, ), onPressed: () async { CouponsHead couponsHead = new CouponsHead(); couponsHead.businessId = coupon.issuer.businessId; couponsHead.expiration = coupon.expiration; couponsHead.couponId = coupon.couponId; couponsHead.quantity = 1; couponsHead.state = "active"; couponsHead.lower = 100; couponsHead.upper = 100; couponsHead.targetProduct = coupon.targetProduct.productID; double price = coupon.targetProduct.unitPrice * (couponsHead.lower / 100); int cost = CouponRateCalculator.getRate(price); acquiring(couponsHead, cost); }, child: Text( "Accept Coupon", style: TextStyle(color: Colors.white), ), ), ), ], ), ); }