基础组件库
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

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