基础组件库
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.

counpon_widget.dart 4.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_base_widget/widgets/goods_details/coupon/bloc/bloc.dart';
  3. import 'package:zhiying_base_widget/widgets/goods_details/coupon/bloc/counpon_repository.dart';
  4. import 'package:zhiying_base_widget/widgets/goods_details/coupon/counpon_sk.dart';
  5. import 'package:zhiying_base_widget/widgets/goods_details/coupon/model/counpon_model.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. import 'package:flutter_bloc/flutter_bloc.dart';
  8. import 'package:cached_network_image/cached_network_image.dart';
  9. ///
  10. /// 优惠券widget
  11. ///
  12. class CounponWidget extends StatelessWidget {
  13. final Map<String, dynamic> model;
  14. const CounponWidget(this.model);
  15. @override
  16. Widget build(BuildContext context) {
  17. // return Container();
  18. return BlocProvider<CounponBloc>(
  19. create: (_) => CounponBloc(repository: CounponRepository())..add(CounponInitEvent(model: model)),
  20. child: CounponWidgetContainer(),
  21. );
  22. }
  23. }
  24. class CounponWidgetContainer extends StatefulWidget {
  25. @override
  26. _CounponWidgetContainerState createState() => _CounponWidgetContainerState();
  27. }
  28. class _CounponWidgetContainerState extends State<CounponWidgetContainer> {
  29. /// 点击领取
  30. void _onJump(CounponModel model) {}
  31. @override
  32. Widget build(BuildContext context) {
  33. return BlocConsumer<CounponBloc, CounponState>(
  34. listener: (context, state) {},
  35. buildWhen: (prev, current) {
  36. if (current is CounponErrorState) {
  37. return false;
  38. }
  39. return true;
  40. },
  41. builder: (context, state) {
  42. if (state is CounponLoadedState) {
  43. return _getMainWdiget(state.model);
  44. }
  45. return CounponSkeleton();
  46. },
  47. );
  48. }
  49. /// 主视图
  50. Widget _getMainWdiget(CounponModel model) {
  51. return Visibility(
  52. visible: !EmptyUtil.isEmpty(model?.coupon_price),
  53. child: GestureDetector(
  54. onTap: () => _onJump(model),
  55. behavior: HitTestBehavior.opaque,
  56. child: Container(
  57. width: double.infinity,
  58. color: Colors.white,
  59. padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 12),
  60. child: Container(
  61. // color: Colors.red,
  62. width: double.infinity,
  63. padding: const EdgeInsets.only(left: 18.5, top: 12, bottom: 14),
  64. decoration: BoxDecoration(
  65. image: DecorationImage(
  66. image: CachedNetworkImageProvider(
  67. model?.bg_img ??'',
  68. ),
  69. fit: BoxFit.fill
  70. )
  71. ),
  72. alignment: Alignment.centerLeft,
  73. child: Row(
  74. children: <Widget>[
  75. /// 价格
  76. _getPriceWidget(model),
  77. const SizedBox(width: 7.5),
  78. /// 有效期
  79. _getTimeWidget(model)
  80. ],
  81. ),
  82. ),
  83. ),
  84. ),
  85. );
  86. }
  87. /// 价格
  88. Widget _getPriceWidget(CounponModel model) {
  89. return Row(
  90. crossAxisAlignment: CrossAxisAlignment.center,
  91. mainAxisAlignment: MainAxisAlignment.center,
  92. children: <Widget>[
  93. /// 价格类型
  94. Text(model?.price_type ?? '¥ ', style: TextStyle(fontSize: 15, color: HexColor.fromHex(model?.price_type_color ?? '#FFFFFF'))),
  95. /// 价格
  96. Text(model?.coupon_price ??'100', style: TextStyle(fontSize: 30, color: HexColor.fromHex(model?.coupon_price_color ?? '#FFFFFF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  97. ],
  98. );
  99. }
  100. /// 名称与有效期
  101. Widget _getTimeWidget(CounponModel model) {
  102. return Column(
  103. crossAxisAlignment: CrossAxisAlignment.start,
  104. children: <Widget>[
  105. /// 标题
  106. Text(model?.coupon_title ?? '优惠券', style: TextStyle(fontSize: 17, color: HexColor.fromHex( model?.coupon_title_color ?? '#FFFFFF'))),
  107. /// 到期时间
  108. Text(model?.coupon_endtime ?? '有效期至2020-10-01', style: TextStyle(fontSize: 10, color: HexColor.fromHex(model?.coupon_time_color ?? '#FFFFFF')))
  109. ],
  110. );
  111. }
  112. }