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

105 line
3.0 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. ///
  9. /// 优惠券widget
  10. ///
  11. class CounponWidget extends StatelessWidget {
  12. final Map<String, dynamic> model;
  13. const CounponWidget(this.model);
  14. @override
  15. Widget build(BuildContext context) {
  16. return Container();
  17. // return BlocProvider<CounponBloc>(
  18. // create: (_) => CounponBloc(repository: CounponRepository())..add(CounponInitEvent(model: model)),
  19. // child: CounponContainer(),
  20. // );
  21. }
  22. }
  23. class CounponContainer extends StatefulWidget {
  24. @override
  25. _CounponContainerState createState() => _CounponContainerState();
  26. }
  27. class _CounponContainerState extends State<CounponContainer> {
  28. /// 点击领取
  29. void _onJump(CounponModel model) {}
  30. @override
  31. Widget build(BuildContext context) {
  32. BlocConsumer<CounponBloc, CounponState>(
  33. listener: (context, state) {},
  34. buildWhen: (prev, current) {
  35. if (current is CounponErrorState) {
  36. return false;
  37. }
  38. return true;
  39. },
  40. builder: (context, state) {
  41. if (state is CounponLoadedState) {
  42. // return _getMainWdiget(state.model);
  43. }
  44. // return CounponSkeleton();
  45. return Container();
  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. margin: const EdgeInsets.only(left: 12.5, right: 12.5),
  57. padding: const EdgeInsets.only(left: 18.5),
  58. alignment: Alignment.centerLeft,
  59. child: Row(
  60. children: <Widget>[
  61. /// 价格
  62. _getPriceWidget(model),
  63. const SizedBox(width: 7.5),
  64. /// 有效期
  65. _getTimeWidget(model)
  66. ],
  67. ),
  68. ),
  69. );
  70. }
  71. /// 价格
  72. Widget _getPriceWidget(CounponModel model) {
  73. return Row(
  74. children: <Widget>[
  75. /// 价格类型
  76. Text('¥', style: TextStyle(fontSize: 15, color: HexColor.fromHex('#FFFFFF'))),
  77. /// 价格
  78. Text('100', style: TextStyle(fontSize: 30, color: HexColor.fromHex('#FFFFFF'))),
  79. ],
  80. );
  81. }
  82. /// 名称与有效期
  83. Widget _getTimeWidget(CounponModel model) {
  84. return Column(
  85. children: <Widget>[
  86. /// 标题
  87. Text('优惠券', style: TextStyle(fontSize: 17, color: HexColor.fromHex('#FFFFFF'))),
  88. /// 到期时间
  89. Text('有效期至2020-10-01', style: TextStyle(fontSize: 10, color: HexColor.fromHex('#FFFFFF')))
  90. ],
  91. );
  92. }
  93. }