import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/separator.dart'; class CouponWidget extends StatefulWidget { final bool isEffective; final bool isUsed; final GestureTapCallback callback; CouponWidget(this.isEffective,this.isUsed,this.callback); @override State createState() { return _CouponWidget(); } } class _CouponWidget extends State { @override Widget build(BuildContext context) { return buildCoupon(); } Widget buildCoupon() { return Container( margin: EdgeInsets.fromLTRB(14, 6, 14, 6), child: AspectRatio( aspectRatio: 2.485, child: Stack( children: [ Image.asset( widget.isEffective ? "assets/image/ic_coupon_bg.png" : "assets/image/ic_coupon_invalid_bg.png", fit: BoxFit.cover, width: double.infinity, height: double.infinity, ), if (!widget.isEffective) Positioned( top: 10, right: 0, child: Transform.rotate( angle: 26, child: Text( S.of(context).yishijiao, style: TextStyle( fontSize: 8, color: Color(0xFF353535), ), ), ), ), Opacity( opacity: widget.isEffective ? 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( "https://t7.baidu.com/it/u=810585695,3039658333&fm=193&f=GIF", width: 60, height: 60, fit: BoxFit.cover, ), ), 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( "黑糖面包兑换券", style: TextStyle( fontWeight: FontWeight.bold, fontSize: 14, color: Color(0xFF353535), ), ), ), if (widget.isEffective) widget.isUsed ? 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); }, ), ], ): Row( children: [ Text( S.of(context).qushiyong, style: TextStyle( color: Color(0xFF32A060), fontSize: 12, ), ), Icon( Icons.keyboard_arrow_right, size: 16, color: Color(0xFF32A060), ) ], ), ], ), ), Expanded( flex: 1, child: Container( margin: EdgeInsets.only(right: 37), alignment: Alignment.center, child: Text( "前往前进麦味任意门店进行实付金额大于0的任意消费即可免费兑换黑糖面包一个", 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( S.of(context).shiyongriqi("2020.01.20~2020.01.21"), 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: [ 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: (){widget.callback();Navigator.of(context).pop();},), 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, ), ], ) ], ); }, ); } }