You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

384 lines
16 KiB

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:teso/Classes/API Clasess/Product.dart';
import 'package:teso/util/SizeConfig.dart';
import 'package:teso/util/consts.dart';
import 'package:teso/Classes/API Clasess/CouponDetails.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
import 'package:teso/Pages/Sub_Pages/ProductDetails/CouponList.dart';
import 'dart:convert';
import 'ProductImage.dart';
class ProductDetails extends StatefulWidget {
final Product product;
const ProductDetails({Key key, this.product}) : super(key: key);
@override
_ProductDetailsState createState() => _ProductDetailsState();
}
enum AppBarBehavior { normal, pinned, floating, snapping }
class _ProductDetailsState extends State<ProductDetails>
with TickerProviderStateMixin {
AnimationController _containerController;
Animation<double> width;
Animation<double> heigth;
double _appBarHeight = 256.0;
AppBarBehavior _appBarBehavior = AppBarBehavior.pinned;
List<CouponDetails> coupons;
int number = 0;
var _future;
Future<List<CouponDetails>> getProductCoupons() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Authorization': prefs.getString('tokensTeso')
};
var register2 = serverLocation + 'coupons/productCoupon';
var client1 = await http.post(Uri.parse(register2),
body: json.encode(widget.product.productID), headers: requestHeaders);
if (client1.statusCode == 200) {
try {
var details = jsonDecode(client1.body);
coupons = List<CouponDetails>.from(
details.map((model) => CouponDetails.fromJSON(model)).toList());
setState(() {
number = coupons.length;
});
return coupons;
} catch (e) {
print(e);
return null;
}
} else {
return null;
}
}
@override
void initState() {
_future = getProductCoupons();
_containerController = new AnimationController(
duration: new Duration(milliseconds: 2000), vsync: this);
super.initState();
width = new Tween<double>(
begin: 200.0,
end: 220.0,
).animate(
new CurvedAnimation(
parent: _containerController,
curve: Curves.ease,
),
);
heigth = new Tween<double>(
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) {
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: <Widget>[
new CustomScrollView(
shrinkWrap: false,
slivers: <Widget>[
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: <Widget>[
GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) {
return ProductImage(
productTag: widget.product.productID,
productImageSRC:
widget.product.productImage,
);
}));
},
child: new Container(
width: width.value,
height: _appBarHeight,
child: Hero(
tag: widget.product.productID,
child: CachedNetworkImage(
imageUrl: tesoProductThumbnail(
productLogo: widget.product.productImage,
width: 640,
height: 640,
),
placeholder: (context, url) => Center(
child: CupertinoActivityIndicator(
animating: true,
radius: 10,
),
),
imageBuilder: (context, imageProvider) =>
Image(
fit: BoxFit.contain,
image: imageProvider,
),
),
),
),
),
],
),
),
),
new SliverList(
delegate: new SliverChildListDelegate(<Widget>[
new Container(
color: Colors.white,
child: new Padding(
padding: const EdgeInsets.all(35.0),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
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: <Widget>[
new Center(
child: new Text(
widget.product.productName
.toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: SizeConfig
.blockSizeHorizontal *
4.0,
),
),
),
new Row(
children: <Widget>[
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.product.unitPrice
.toString()),
)
],
),
new Row(
children: <Widget>[
new Icon(
Icons.shopping_basket,
),
new Padding(
padding:
const EdgeInsets.all(8.0),
child: new Text(
"Coupons Available : ",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
new Padding(
padding:
const EdgeInsets.all(8.0),
child:
new Text(number.toString()),
)
],
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new Row(
children: <Widget>[
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.product
.businessID !=
null
? widget.product.businessID
.toUpperCase()
: ""),
)
],
),
),
],
),
),
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.product.productDesc != null
? widget.product.productDesc
: "",
style: TextStyle(
fontSize:
SizeConfig.blockSizeHorizontal * 3.5,
),
),
SizedBox(
height: 50,
),
],
),
),
),
),
]),
),
],
),
FutureBuilder(
future: _future,
builder: (context, snapshot) {
if (coupons == null || number == 0) {
return Container();
} else {
return Container(
height: 100.0,
padding: EdgeInsets.all(20),
child: new TextButton(
onPressed: () => Navigator.of(context).push(
PageRouteBuilder(
opaque: false,
pageBuilder: (_, __, ___) => CouponList(
couponsList: coupons,
),
),
),
child: new Container(
height: 100.0,
alignment: Alignment.center,
decoration: new BoxDecoration(
color: tesoGold,
borderRadius: new BorderRadius.circular(60.0),
),
child: new Text(
"View Coupons",
style: new TextStyle(color: Colors.white),
),
),
),
);
}
}),
],
),
),
),
),
);
}
}