基础组件库
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

counpon_widget.dart 5.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:zhiying_base_widget/widgets/goods_details/coupon/bloc/bloc.dart';
  4. import 'package:zhiying_base_widget/widgets/goods_details/coupon/bloc/counpon_repository.dart';
  5. import 'package:zhiying_base_widget/widgets/goods_details/coupon/counpon_sk.dart';
  6. import 'package:zhiying_base_widget/widgets/goods_details/coupon/model/counpon_model.dart';
  7. import 'package:zhiying_comm/zhiying_comm.dart';
  8. import 'package:flutter_bloc/flutter_bloc.dart';
  9. import 'package:cached_network_image/cached_network_image.dart';
  10. import 'package:provider/provider.dart';
  11. import 'package:zhiying_comm/util/turn_chain/turn_chain_util.dart';
  12. ///
  13. /// 优惠券widget
  14. ///
  15. class CounponWidget extends StatelessWidget {
  16. final Map<String, dynamic> model;
  17. const CounponWidget(this.model);
  18. @override
  19. Widget build(BuildContext context) {
  20. // return Container();
  21. return BlocProvider<CounponBloc>(
  22. create: (_) => CounponBloc(repository: CounponRepository()), //..add(CounponInitEvent(model: model)),
  23. child: CounponWidgetContainer(
  24. model,
  25. key: UniqueKey(),
  26. ),
  27. );
  28. }
  29. }
  30. class CounponWidgetContainer extends StatefulWidget {
  31. final Map<String, dynamic> model;
  32. const CounponWidgetContainer(this.model, {Key key}) : super(key: key);
  33. @override
  34. _CounponWidgetContainerState createState() => _CounponWidgetContainerState();
  35. }
  36. class _CounponWidgetContainerState extends State<CounponWidgetContainer> {
  37. UserInfoModel _user;
  38. @override
  39. void initState() {
  40. BlocProvider.of<CounponBloc>(context).add(CounponInitEvent(model: widget?.model));
  41. super.initState();
  42. }
  43. @override
  44. void didChangeDependencies() {
  45. _user = Provider.of<UserInfoNotifier>(context).userInfo;
  46. super.didChangeDependencies();
  47. }
  48. /// 点击领取
  49. void _onJump(CounponModel model) async{
  50. if (EmptyUtil.isEmpty(model?.convertArgs)) {
  51. Fluttertoast.showToast(msg: '商品信息正在加载中,请稍后再试~');
  52. return;
  53. }
  54. TurnChainUtil.openReceiveCoupon(context, _user, model?.good_id, model.provider, model?.convertArgs?.toJson());
  55. }
  56. @override
  57. Widget build(BuildContext context) {
  58. return BlocConsumer<CounponBloc, CounponState>(
  59. listener: (context, state) {},
  60. buildWhen: (prev, current) {
  61. if (current is CounponErrorState) {
  62. return false;
  63. }
  64. return true;
  65. },
  66. builder: (context, state) {
  67. if (state is CounponLoadedState) {
  68. return _getMainWidget(state.model);
  69. }
  70. return CounponSkeleton();
  71. },
  72. );
  73. }
  74. /// 主视图
  75. Widget _getMainWidget(CounponModel model) {
  76. return Visibility(
  77. visible: !EmptyUtil.isEmpty(model?.coupon_price),
  78. child: GestureDetector(
  79. onTap: () => _onJump(model),
  80. behavior: HitTestBehavior.opaque,
  81. child: Container(
  82. width: double.infinity,
  83. decoration: BoxDecoration(
  84. color: HexColor.fromHex(model?.bgColor),
  85. borderRadius: BorderRadius.only(
  86. topLeft: Radius.circular(ParseUtil.stringParseDouble(model?.topLeftRadius)),
  87. topRight: Radius.circular(ParseUtil.stringParseDouble(model?.topRightRadius)),
  88. bottomLeft: Radius.circular(ParseUtil.stringParseDouble(model?.bottomLeftRadius)),
  89. bottomRight: Radius.circular(ParseUtil.stringParseDouble(model?.bottomRightRadius))
  90. )
  91. ),
  92. margin: EdgeInsets.only(top: ParseUtil.stringParseDouble(model?.topMargin), left: ParseUtil.stringParseDouble(model?.leftRightMargin), right: ParseUtil.stringParseDouble(model?.leftRightMargin)),
  93. padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 6, bottom: 6),
  94. child: Container(
  95. // color: Colors.red,
  96. width: double.infinity,
  97. padding: const EdgeInsets.only(left: 18.5, top: 12, bottom: 14),
  98. decoration: BoxDecoration(
  99. image: DecorationImage(
  100. image: CachedNetworkImageProvider(
  101. model?.bgImage ?? '',
  102. ),
  103. fit: BoxFit.fill)),
  104. alignment: Alignment.centerLeft,
  105. child: Row(
  106. children: <Widget>[
  107. /// 价格
  108. _getPriceWidget(model),
  109. const SizedBox(width: 7.5),
  110. /// 有效期
  111. _getTimeWidget(model)
  112. ],
  113. ),
  114. ),
  115. ),
  116. ),
  117. );
  118. }
  119. /// 价格
  120. Widget _getPriceWidget(CounponModel model) {
  121. return Row(
  122. crossAxisAlignment: CrossAxisAlignment.center,
  123. mainAxisAlignment: MainAxisAlignment.center,
  124. children: <Widget>[
  125. /// 价格类型
  126. Text('¥ ', style: TextStyle(fontSize: 15, color: HexColor.fromHex(model?.couponPriceColor ?? '#FFFFFF'))),
  127. /// 价格
  128. Text(model?.coupon_price ?? '100',
  129. style: TextStyle(fontSize: 30, color: HexColor.fromHex(model?.couponPriceColor ?? '#FFFFFF'), fontFamily: 'Din', package: 'zhiying_comm')),
  130. ],
  131. );
  132. }
  133. /// 名称与有效期
  134. Widget _getTimeWidget(CounponModel model) {
  135. return Column(
  136. crossAxisAlignment: CrossAxisAlignment.start,
  137. children: <Widget>[
  138. /// 标题
  139. Text(model?.couponText ?? '优惠券', style: TextStyle(fontSize: 17, color: HexColor.fromHex(model?.couponTextColor ?? '#FFFFFF'))),
  140. /// 到期时间
  141. Visibility(
  142. visible: !EmptyUtil.isEmpty(model?.coupon_endtime),
  143. child: Text(model?.coupon_endtime ?? '有效期至2020-10-01', style: TextStyle(fontSize: 10, color: HexColor.fromHex(model?.couponTimeColor ?? '#FFFFFF'))))
  144. ],
  145. );
  146. }
  147. }