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.
312 lines
13 KiB
312 lines
13 KiB
import 'dart:math'; |
|
|
|
import 'package:flutter/material.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/coupon.dart'; |
|
import 'package:huixiang/view_widget/round_button.dart'; |
|
import 'package:huixiang/view_widget/separator.dart'; |
|
|
|
class CouponWidget extends StatelessWidget { |
|
final GestureTapCallback callback; |
|
final Coupon coupon; |
|
|
|
CouponWidget(this.coupon, this.callback); |
|
|
|
// |
|
// @override |
|
// State<StatefulWidget> createState() { |
|
// return _CouponWidget(); |
|
// } |
|
// } |
|
// |
|
// class _CouponWidget extends State<CouponWidget> { |
|
@override |
|
Widget build(BuildContext context) { |
|
return buildCoupon(context); |
|
} |
|
|
|
Widget buildCoupon(BuildContext context) { |
|
return Container( |
|
margin: EdgeInsets.fromLTRB(14, 6, 14, 6), |
|
child: AspectRatio( |
|
aspectRatio: 2.485, |
|
child: Stack( |
|
children: [ |
|
Image.asset( |
|
coupon.status != 3 |
|
? "assets/image/ic_coupon_bg.png" |
|
: "assets/image/ic_coupon_invalid_bg.png", |
|
fit: BoxFit.cover, |
|
width: double.infinity, |
|
height: double.infinity, |
|
), |
|
if (coupon.status == 3) |
|
Positioned( |
|
top: 10, |
|
right: 0, |
|
child: Transform.rotate( |
|
angle: pi / 5.0, |
|
child: Text( |
|
S.of(context).yishijiao, //已失效 |
|
style: TextStyle( |
|
fontSize: 8, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
), |
|
), |
|
Opacity( |
|
opacity: coupon.status != 3 ? 1 : 0.54, |
|
child: Container( |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Expanded( |
|
flex: 7, |
|
child: Container( |
|
padding: EdgeInsets.only(top: 18, bottom: 20), |
|
child: Row( |
|
children: [ |
|
Container( |
|
margin: EdgeInsets.only(left: 20), |
|
child: Image.network( |
|
(coupon == null || |
|
coupon.couponImg == null || |
|
coupon.couponImg == "") |
|
? "" |
|
: coupon.couponImg, |
|
width: 60, |
|
height: 60, |
|
fit: BoxFit.cover, |
|
errorBuilder: (context, error, e) { |
|
return Image.asset( |
|
"assets/image/default_avatar.png"); |
|
}, |
|
), |
|
), |
|
Expanded( |
|
flex: 1, |
|
child: Container( |
|
height: 60, |
|
margin: EdgeInsets.only(left: 12), |
|
child: Column( |
|
mainAxisAlignment: |
|
MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Container( |
|
margin: EdgeInsets.only(right: 15), |
|
child: Row( |
|
children: [ |
|
Expanded( |
|
flex: 1, |
|
child: Text( |
|
coupon.couponName ?? "", |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 14, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
), |
|
(coupon.status == 0) |
|
? Row( |
|
children: [ |
|
RoundButton( |
|
width: 42, |
|
height: 21, |
|
text: |
|
S.of(context).lingqu, |
|
textColor: Colors.white, |
|
fontSize: 12, |
|
padding: EdgeInsets.only( |
|
top: 2, |
|
bottom: 2, |
|
left: 8, |
|
right: 8), |
|
backgroup: |
|
Color(0xff32A060), |
|
callback: () { |
|
showAlertDialog( |
|
context); |
|
}, |
|
), |
|
], |
|
) |
|
: (coupon.status == 1) |
|
? Row( |
|
children: [ |
|
Text( |
|
S |
|
.of(context) |
|
.qushiyong, |
|
style: TextStyle( |
|
color: Color( |
|
0xFF32A060), |
|
fontSize: 12, |
|
), |
|
), |
|
Icon( |
|
Icons |
|
.keyboard_arrow_right, |
|
size: 16, |
|
color: |
|
Color(0xFF32A060), |
|
) |
|
], |
|
) |
|
: Container(), |
|
], |
|
), |
|
), |
|
Expanded( |
|
flex: 1, |
|
child: Container( |
|
margin: EdgeInsets.only(right: 37), |
|
alignment: Alignment.centerLeft, |
|
child: Text( |
|
coupon.couponDescription ?? "", |
|
style: TextStyle( |
|
fontSize: 10, |
|
color: Color(0xFF4C4C4C), |
|
), |
|
), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
Container( |
|
margin: EdgeInsets.only(left: 23, right: 23), |
|
child: MySeparator( |
|
width: 5, |
|
height: 1, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
Expanded( |
|
flex: 3, |
|
child: Container( |
|
padding: EdgeInsets.only(left: 20), |
|
alignment: Alignment.centerLeft, |
|
child: Text( |
|
coupon.status == 0 |
|
? S.of(context).faxingshijian(coupon.publishStartTime) |
|
: coupon.status == 1 |
|
? S.of(context).lingqushijian(coupon.receiveTime) |
|
: S.of(context).shiyongriqi(coupon.useTime), |
|
style: TextStyle( |
|
color: Color(0xFF727272), |
|
fontSize: 10, |
|
), |
|
), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
); |
|
} |
|
|
|
showAlertDialog(BuildContext context) { |
|
//显示对话框 |
|
showDialog( |
|
context: context, |
|
builder: (BuildContext context) { |
|
return SimpleDialog( |
|
titlePadding: EdgeInsets.all(10), |
|
backgroundColor: Colors.transparent, |
|
elevation: 0, |
|
shape: RoundedRectangleBorder( |
|
borderRadius: BorderRadius.all(Radius.circular(6))), |
|
children: <Widget>[ |
|
Stack( |
|
alignment: Alignment.topCenter, |
|
children: [ |
|
Container( |
|
margin: EdgeInsets.only(top: 40), |
|
decoration: new BoxDecoration( |
|
color: Colors.white, |
|
borderRadius: BorderRadius.all(Radius.circular(8))), |
|
width: 218, |
|
height: 210, |
|
child: Column( |
|
children: [ |
|
Padding( |
|
padding: EdgeInsets.only(top: 50, bottom: 19), |
|
child: Text( |
|
"领取成功", |
|
style: TextStyle( |
|
color: Color(0xff353535), |
|
fontSize: 16, |
|
fontWeight: FontWeight.bold), |
|
), |
|
), |
|
Text( |
|
"您已成功领取优惠劵,请在", |
|
style: |
|
TextStyle(color: Color(0xff353535), fontSize: 14), |
|
), |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
children: [ |
|
GestureDetector( |
|
child: Text( |
|
"卡包-可使用", |
|
style: TextStyle( |
|
color: Color(0xffFF7A1A), |
|
fontSize: 14, |
|
fontWeight: FontWeight.bold), |
|
), |
|
onTap: callback, |
|
), |
|
Text( |
|
"中查看", |
|
style: TextStyle( |
|
color: Color(0xff353535), fontSize: 14), |
|
), |
|
], |
|
), |
|
Padding( |
|
padding: EdgeInsets.only(top: 30), |
|
child: RoundButton( |
|
width: 130, |
|
height: 34, |
|
text: S.of(context).queren, |
|
textColor: Colors.white, |
|
fontSize: 12, |
|
callback: () { |
|
Navigator.of(context).pop(); |
|
}, |
|
padding: EdgeInsets.only( |
|
top: 2, bottom: 2, left: 8, right: 8), |
|
backgroup: Color(0xff32A060), |
|
), |
|
) |
|
], |
|
), |
|
), |
|
Image.asset( |
|
"assets/image/icon_order_success.png", |
|
fit: BoxFit.cover, |
|
width: 80, |
|
height: 80, |
|
), |
|
], |
|
) |
|
], |
|
); |
|
}, |
|
); |
|
} |
|
}
|
|
|