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

133 lines
4.1 KiB

  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:zhiying_base_widget/widgets/custom/search/model/custom_search_model.dart';
  4. import 'package:zhiying_comm/zhiying_comm.dart';
  5. ///
  6. /// 通用模块的搜索栏
  7. ///
  8. class CustomSearchWidget extends StatelessWidget {
  9. final Map<String, dynamic> data;
  10. CustomSearchModel model;
  11. CustomSearchWidget(this.data, {Key key}) : super(key: key) {
  12. try {
  13. model = CustomSearchModel.fromJson(jsonDecode(data['data']));
  14. } catch (e, s) {
  15. Logger.warn(e, s);
  16. }
  17. }
  18. // 点击事件
  19. void _onClickListener(BuildContext context, SkipModel skipModel) {
  20. if (!EmptyUtil.isEmpty(skipModel)) {
  21. RouterUtil.route(skipModel, skipModel.toJson(), context);
  22. }
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return Container(
  27. width: double.infinity,
  28. decoration: BoxDecoration(
  29. color: HexColor.fromHex(model?.bgColor),
  30. ),
  31. padding: const EdgeInsets.symmetric(horizontal: 12.5, vertical: 4),
  32. child: _buildMainWidget(context));
  33. }
  34. Widget _buildMainWidget(BuildContext context) {
  35. if (EmptyUtil.isEmpty(model)) return Container();
  36. Widget rlt;
  37. switch (model.moduleType) {
  38. case 'search_1':
  39. rlt = _buildStyle1Widget(context);
  40. break;
  41. case 'search_2':
  42. rlt = _buildStyle2Widget(context);
  43. break;
  44. default:
  45. rlt = Container();
  46. break;
  47. }
  48. return rlt;
  49. }
  50. /// 右1图标
  51. Widget _buildStyle1Widget(BuildContext context) {
  52. return Row(
  53. children: <Widget>[
  54. Expanded(
  55. child: GestureDetector(
  56. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  57. behavior: HitTestBehavior.opaque,
  58. child: Container(
  59. // height: 30,
  60. width: double.infinity,
  61. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 9),
  62. decoration: BoxDecoration(borderRadius: BorderRadius.circular(60 / 2), color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor)),
  63. child: Row(
  64. children: <Widget>[
  65. CachedNetworkImage(
  66. width: 13,
  67. height: 13,
  68. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  69. ),
  70. SizedBox(width: 4),
  71. Text(model?.listStyle?.searchCss?.text ?? '输入搜索内容,领券省钱', style: TextStyle(fontSize: 13, color: HexColor.fromHex('#FFFFFFFF')))
  72. ],
  73. ),
  74. ),
  75. )),
  76. SizedBox(width: 10),
  77. GestureDetector(
  78. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  79. child: CachedNetworkImage(
  80. width: 30,
  81. height: 30,
  82. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  83. )),
  84. ],
  85. );
  86. }
  87. /// 无图标
  88. Widget _buildStyle2Widget(BuildContext context) {
  89. return GestureDetector(
  90. behavior: HitTestBehavior.opaque,
  91. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  92. child: Container(
  93. width: double.infinity,
  94. child: Container(
  95. width: double.infinity,
  96. decoration: BoxDecoration(
  97. borderRadius: BorderRadius.circular(40),
  98. color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor ?? '#F9F9F9'),
  99. ),
  100. padding: const EdgeInsets.symmetric(vertical: 6),
  101. child: Row(
  102. mainAxisAlignment: MainAxisAlignment.center,
  103. children: <Widget>[
  104. /// 搜索按钮
  105. CachedNetworkImage(
  106. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  107. height: 20,
  108. width: 20,
  109. ),
  110. const SizedBox(width: 7.5),
  111. /// 提示文字
  112. Text(
  113. model?.listStyle?.searchCss?.text ?? '搜索更多优惠商品',
  114. style: TextStyle(fontSize: 14, color: HexColor.fromHex(model?.listStyle?.searchCss?.textColor ?? '#999999')),
  115. )
  116. ],
  117. ),
  118. ),
  119. ),
  120. );
  121. }
  122. }