import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:teso/util/consts.dart'; import 'package:teso/Classes/API Clasess/CouponDetails.dart'; import 'package:teso/Classes/API Clasess/CouponHead.dart'; buildRecentItem( BuildContext context, CouponDetails couponDetails, Function purchase) { bool active; if (couponDetails.quantity! > 0) { active = true; } else { active = false; } return Container( width: MediaQuery.of(context).size.width, height: 150, child: Row( children: [ Container( width: 95, height: 95, decoration: BoxDecoration( border: Border.all( color: Colors.grey, width: 0.5, ), borderRadius: BorderRadius.only( topRight: Radius.circular(30), topLeft: Radius.circular(30), bottomLeft: Radius.circular(30), bottomRight: Radius.circular(30), ), ), child: ClipRRect( borderRadius: BorderRadius.only( topLeft: Radius.circular(30.0), topRight: Radius.circular(30.0), bottomLeft: Radius.circular(30), bottomRight: Radius.circular(30), ), child: CachedNetworkImage( imageUrl: productURL + couponDetails.targetProduct!.productImage!, imageBuilder: (context, imageProvider) => Image( width: MediaQuery.of(context).size.width * 0.28, height: 110, fit: BoxFit.fill, image: imageProvider, ), ), ), ), Container( padding: EdgeInsets.only(top: 10, left: 10), height: 150, width: MediaQuery.of(context).size.width - (MediaQuery.of(context).size.width * 0.35), child: Column( children: [ Container( width: MediaQuery.of(context).size.width - (MediaQuery.of(context).size.width * 0.35), height: 30, child: Stack( children: [ Container( width: double.infinity, height: double.infinity, child: Align( alignment: Alignment.centerLeft, child: Text( couponDetails.issuer!.businessName!, style: TextStyle( fontSize: 12.5, color: Colors.grey, ), textAlign: TextAlign.left, ), ), ), Container( width: double.infinity, height: double.infinity, child: Align( alignment: Alignment.centerRight, child: Text( couponDetails.lowerLimit.toString() + " - " + couponDetails.upperLimit.toString() + "%", textAlign: TextAlign.left, style: TextStyle( fontWeight: FontWeight.bold, ), ), ), ), ], ), ), Container( width: MediaQuery.of(context).size.width - (MediaQuery.of(context).size.width * 0.35), child: Text( couponDetails.targetProduct!.productName!, textAlign: TextAlign.left, ), ), Container( width: MediaQuery.of(context).size.width - (MediaQuery.of(context).size.width * 0.35), child: Text( "Cost : GH¢ " + couponDetails.targetProduct!.unitPrice.toString(), textAlign: TextAlign.left, ), ), Visibility( visible: active, child: Container( width: MediaQuery.of(context).size.width - (MediaQuery.of(context).size.width * 0.25), child: Align( alignment: Alignment.centerRight, child: ElevatedButton( style: ElevatedButton.styleFrom( primary: accentMain, shape: RoundedRectangleBorder( borderRadius: BorderRadius.all( Radius.circular(20.0), ), ), ), onPressed: () async { CouponsHead couponHeads = new CouponsHead(); couponHeads.businessId = couponDetails.businessId; couponHeads.couponId = couponDetails.couponId; couponHeads.expiration = couponDetails.expiration; couponHeads.lower = couponDetails.lowerLimit; couponHeads.upper = couponDetails.upperLimit; couponHeads.type = couponDetails.type; couponHeads.quantity = 1; couponHeads.targetProduct = couponDetails.targetProduct!.productID; purchase(context, couponHeads, couponDetails.targetProduct!.unitPrice); }, child: Text("Acquire Coupon"), ), ), ), ), Visibility( visible: !active, child: Container( width: MediaQuery.of(context).size.width - (MediaQuery.of(context).size.width * 0.25), child: Align( alignment: Alignment.centerRight, child: Text( "Sold Out", style: TextStyle( color: Theme.of(context).colorScheme.secondary, ), ), ), ), ), Divider(), ], ), ), ], ), ); }