基础组件库
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

121 行
3.8 KiB

  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 GestureDetector(
  52. onTap: () => _onJump(model),
  53. behavior: HitTestBehavior.opaque,
  54. child: Container(
  55. width: double.infinity,
  56. color: Colors.white,
  57. padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 12),
  58. child: Container(
  59. // color: Colors.red,
  60. width: double.infinity,
  61. padding: const EdgeInsets.only(left: 18.5, top: 12, bottom: 14),
  62. decoration: BoxDecoration(
  63. image: DecorationImage(
  64. image: CachedNetworkImageProvider(
  65. model?.bg_img ??'',
  66. ),
  67. fit: BoxFit.fill
  68. )
  69. ),
  70. alignment: Alignment.centerLeft,
  71. child: Row(
  72. children: <Widget>[
  73. /// 价格
  74. _getPriceWidget(model),
  75. const SizedBox(width: 7.5),
  76. /// 有效期
  77. _getTimeWidget(model)
  78. ],
  79. ),
  80. ),
  81. ),
  82. );
  83. }
  84. /// 价格
  85. Widget _getPriceWidget(CounponModel model) {
  86. return Row(
  87. crossAxisAlignment: CrossAxisAlignment.center,
  88. mainAxisAlignment: MainAxisAlignment.center,
  89. children: <Widget>[
  90. /// 价格类型
  91. Text(model?.price_type ?? '¥ ', style: TextStyle(fontSize: 15, color: HexColor.fromHex(model?.price_type_color ?? '#FFFFFF'))),
  92. /// 价格
  93. Text(model?.coupon_price ??'100', style: TextStyle(fontSize: 30, color: HexColor.fromHex(model?.coupon_price_color ?? '#FFFFFF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  94. ],
  95. );
  96. }
  97. /// 名称与有效期
  98. Widget _getTimeWidget(CounponModel model) {
  99. return Column(
  100. crossAxisAlignment: CrossAxisAlignment.start,
  101. children: <Widget>[
  102. /// 标题
  103. Text(model?.coupon_title ?? '优惠券', style: TextStyle(fontSize: 17, color: HexColor.fromHex( model?.coupon_title_color ?? '#FFFFFF'))),
  104. /// 到期时间
  105. Text(model?.coupon_endtime ?? '有效期至2020-10-01', style: TextStyle(fontSize: 10, color: HexColor.fromHex(model?.coupon_time_color ?? '#FFFFFF')))
  106. ],
  107. );
  108. }
  109. }