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.
226 lines
6.8 KiB
226 lines
6.8 KiB
import 'package:flutter/material.dart';
|
|
import 'package:teso/Classes/API Clasess/CouponHead.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:teso/Classes/CouponRateCalculator.dart';
|
|
import 'package:teso/providers/device_provider.dart';
|
|
import 'package:teso/util/consts.dart';
|
|
|
|
class AcquireCoupon extends StatefulWidget {
|
|
final CouponsHead head;
|
|
final double price;
|
|
|
|
const AcquireCoupon({Key key, this.head, this.price}) : super(key: key);
|
|
@override
|
|
_AcquireCouponState createState() => _AcquireCouponState(head: this.head);
|
|
}
|
|
|
|
class _AcquireCouponState extends State<AcquireCoupon> {
|
|
final CouponsHead head;
|
|
_AcquireCouponState({this.head});
|
|
double _value;
|
|
int _n = 1;
|
|
int coinCost = 0;
|
|
|
|
changeValue(val) {
|
|
setState(() {
|
|
_value = val;
|
|
});
|
|
calcCost();
|
|
}
|
|
|
|
calcCost() {
|
|
double price = widget.price * (_value / 100);
|
|
|
|
coinCost = CouponRateCalculator.getRate(price);
|
|
|
|
coinCost = coinCost * _n;
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
_value = head.lower;
|
|
calcCost();
|
|
super.initState();
|
|
}
|
|
|
|
void add() {
|
|
setState(() {
|
|
_n++;
|
|
});
|
|
calcCost();
|
|
}
|
|
|
|
void minus() {
|
|
setState(() {
|
|
if (_n != 1) _n--;
|
|
});
|
|
calcCost();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(
|
|
horizontal: (MediaQuery.of(context).size.width) * 0.030,
|
|
vertical: (MediaQuery.of(context).size.width) * 0.040,
|
|
),
|
|
child: Material(
|
|
child: new Wrap(children: <Widget>[
|
|
new Container(
|
|
width: double.infinity,
|
|
margin: EdgeInsets.only(
|
|
top: 20.0,
|
|
bottom: 12.0,
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
"ACQUIRE COUPON",
|
|
style: TextStyle(
|
|
fontSize: 20.0,
|
|
),
|
|
),
|
|
)),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
|
child: Divider(),
|
|
),
|
|
new ListTile(
|
|
title: new Container(
|
|
child: new Center(
|
|
child: new Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: <Widget>[
|
|
Text("Quantity"),
|
|
new Container(
|
|
width: 30,
|
|
height: 30,
|
|
child: new FloatingActionButton(
|
|
onPressed: minus,
|
|
child: Text(
|
|
"-",
|
|
style: TextStyle(
|
|
fontSize: 25,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
backgroundColor: Colors.white,
|
|
),
|
|
),
|
|
new Text('$_n', style: new TextStyle(fontSize: 20.0)),
|
|
new Container(
|
|
width: 30,
|
|
height: 30,
|
|
child: new FloatingActionButton(
|
|
onPressed: add,
|
|
child: new Icon(
|
|
Icons.add,
|
|
color: Colors.black,
|
|
size: 20,
|
|
),
|
|
backgroundColor: Colors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
child: head.type.toLowerCase().contains("freebie")
|
|
? Center(
|
|
child: Text("Coupon Type : FREEBIE"),
|
|
)
|
|
: Row(
|
|
children: [
|
|
Text(head.lower.toString() + " %"),
|
|
Slider(
|
|
value: _value,
|
|
min: head.lower,
|
|
max: head.upper,
|
|
divisions: 20,
|
|
activeColor: accentMain,
|
|
inactiveColor: darkAccent,
|
|
label: _value.toString() + "%",
|
|
onChanged: (double newValue) => changeValue(newValue),
|
|
),
|
|
Text(head.upper.toString() + " %"),
|
|
],
|
|
),
|
|
),
|
|
Center(
|
|
child: Wrap(
|
|
direction: Axis.horizontal,
|
|
children: [
|
|
Container(
|
|
child: Container(
|
|
height: 40.0,
|
|
width: 40.0,
|
|
decoration: new BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Container(
|
|
width: 40,
|
|
height: 40,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(50.0),
|
|
topRight: Radius.circular(50.0),
|
|
bottomLeft: Radius.circular(50),
|
|
bottomRight: Radius.circular(50),
|
|
),
|
|
child: Image(
|
|
height: 40,
|
|
width: 40,
|
|
fit: BoxFit.fill,
|
|
image: AssetImage("assets/images/silver1.png"),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
width: 40,
|
|
height: 40,
|
|
child: Center(
|
|
child: Text(
|
|
coinCost.toString(),
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
new ListTile(
|
|
title: new ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
primary: accentMain,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(20.0),
|
|
),
|
|
),
|
|
),
|
|
onPressed: coinCost == 0
|
|
? null
|
|
: () async {
|
|
head.lower = _value;
|
|
head.quantity = _n;
|
|
await Provider.of<DeviceProvider>(context, listen: false)
|
|
.acceptCoupon(head, coinCost, context);
|
|
},
|
|
child: Text("Confirm"),
|
|
),
|
|
onTap: () => {},
|
|
),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|