基础组件库
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

153 lignes
4.8 KiB

  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. TurnChainUtil.openReceiveCoupon(context, _user, model.provider, model.toJson());
  51. }
  52. @override
  53. Widget build(BuildContext context) {
  54. return BlocConsumer<CounponBloc, CounponState>(
  55. listener: (context, state) {},
  56. buildWhen: (prev, current) {
  57. if (current is CounponErrorState) {
  58. return false;
  59. }
  60. return true;
  61. },
  62. builder: (context, state) {
  63. if (state is CounponLoadedState) {
  64. return _getMainWdiget(state.model);
  65. }
  66. return CounponSkeleton();
  67. },
  68. );
  69. }
  70. /// 主视图
  71. Widget _getMainWdiget(CounponModel model) {
  72. return Visibility(
  73. visible: !EmptyUtil.isEmpty(model?.coupon_price),
  74. child: GestureDetector(
  75. onTap: () => _onJump(model),
  76. behavior: HitTestBehavior.opaque,
  77. child: Container(
  78. width: double.infinity,
  79. color: Colors.white,
  80. padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 12),
  81. child: Container(
  82. // color: Colors.red,
  83. width: double.infinity,
  84. padding: const EdgeInsets.only(left: 18.5, top: 12, bottom: 14),
  85. decoration: BoxDecoration(
  86. image: DecorationImage(
  87. image: CachedNetworkImageProvider(
  88. model?.bg_img ?? '',
  89. ),
  90. fit: BoxFit.fill)),
  91. alignment: Alignment.centerLeft,
  92. child: Row(
  93. children: <Widget>[
  94. /// 价格
  95. _getPriceWidget(model),
  96. const SizedBox(width: 7.5),
  97. /// 有效期
  98. _getTimeWidget(model)
  99. ],
  100. ),
  101. ),
  102. ),
  103. ),
  104. );
  105. }
  106. /// 价格
  107. Widget _getPriceWidget(CounponModel model) {
  108. return Row(
  109. crossAxisAlignment: CrossAxisAlignment.center,
  110. mainAxisAlignment: MainAxisAlignment.center,
  111. children: <Widget>[
  112. /// 价格类型
  113. Text(model?.price_type ?? '¥ ', style: TextStyle(fontSize: 15, color: HexColor.fromHex(model?.price_type_color ?? '#FFFFFF'))),
  114. /// 价格
  115. Text(model?.coupon_price ?? '100',
  116. style: TextStyle(fontSize: 30, color: HexColor.fromHex(model?.coupon_price_color ?? '#FFFFFF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  117. ],
  118. );
  119. }
  120. /// 名称与有效期
  121. Widget _getTimeWidget(CounponModel model) {
  122. return Column(
  123. crossAxisAlignment: CrossAxisAlignment.start,
  124. children: <Widget>[
  125. /// 标题
  126. Text(model?.coupon_title ?? '优惠券', style: TextStyle(fontSize: 17, color: HexColor.fromHex(model?.coupon_title_color ?? '#FFFFFF'))),
  127. /// 到期时间
  128. Visibility(
  129. visible: !EmptyUtil.isEmpty(model?.coupon_endtime),
  130. child: Text(model?.coupon_endtime ?? '有效期至2020-10-01', style: TextStyle(fontSize: 10, color: HexColor.fromHex(model?.coupon_time_color ?? '#FFFFFF'))))
  131. ],
  132. );
  133. }
  134. }