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

140 lines
4.7 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. padding: EdgeInsets.symmetric(horizontal: ParseUtil.stringParseDouble(model?.leftRightMargin, defVal: 12.5), vertical: 4),
  29. margin: EdgeInsets.only(top: ParseUtil.stringParseDouble(model?.topMargin)),
  30. decoration: BoxDecoration(
  31. color: HexColor.fromHex(model?.bgColor),
  32. // color: Colors.blueAccent,
  33. borderRadius: BorderRadius.only(
  34. bottomRight: Radius.circular(ParseUtil.stringParseDouble(model?.bottomRightRadius)),
  35. bottomLeft: Radius.circular(ParseUtil.stringParseDouble(model?.bottomLeftRadius)),
  36. topLeft: Radius.circular(ParseUtil.stringParseDouble(model?.topLeftRadius)),
  37. topRight: Radius.circular(ParseUtil.stringParseDouble(model?.topRightRadius)),
  38. )),
  39. child: _buildMainWidget(context));
  40. }
  41. Widget _buildMainWidget(BuildContext context) {
  42. if (EmptyUtil.isEmpty(model)) return Container();
  43. Widget rlt;
  44. switch (model.moduleType) {
  45. case 'search_1':
  46. rlt = _buildStyle1Widget(context);
  47. break;
  48. case 'search_2':
  49. rlt = _buildStyle2Widget(context);
  50. break;
  51. default:
  52. rlt = Container();
  53. break;
  54. }
  55. return rlt;
  56. }
  57. /// 右1图标
  58. Widget _buildStyle1Widget(BuildContext context) {
  59. return Row(
  60. children: <Widget>[
  61. Expanded(
  62. child: GestureDetector(
  63. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  64. behavior: HitTestBehavior.opaque,
  65. child: Container(
  66. // height: 30,
  67. width: double.infinity,
  68. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 9),
  69. decoration: BoxDecoration(borderRadius: BorderRadius.circular(60 / 2), color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor)),
  70. child: Row(
  71. children: <Widget>[
  72. CachedNetworkImage(
  73. width: 13,
  74. height: 13,
  75. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  76. ),
  77. SizedBox(width: 4),
  78. Text(model?.listStyle?.searchCss?.text ?? '输入搜索内容,领券省钱', style: TextStyle(fontSize: 13, color: HexColor.fromHex('#FFFFFFFF')))
  79. ],
  80. ),
  81. ),
  82. )),
  83. SizedBox(width: 10),
  84. GestureDetector(
  85. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  86. child: CachedNetworkImage(
  87. width: 30,
  88. height: 30,
  89. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  90. )),
  91. ],
  92. );
  93. }
  94. /// 无图标
  95. Widget _buildStyle2Widget(BuildContext context) {
  96. return GestureDetector(
  97. behavior: HitTestBehavior.opaque,
  98. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  99. child: Container(
  100. width: double.infinity,
  101. child: Container(
  102. width: double.infinity,
  103. decoration: BoxDecoration(
  104. borderRadius: BorderRadius.circular(40),
  105. color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor ?? '#F9F9F9'),
  106. ),
  107. padding: const EdgeInsets.symmetric(vertical: 6),
  108. child: Row(
  109. mainAxisAlignment: MainAxisAlignment.center,
  110. children: <Widget>[
  111. /// 搜索按钮
  112. CachedNetworkImage(
  113. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  114. height: 20,
  115. width: 20,
  116. ),
  117. const SizedBox(width: 7.5),
  118. /// 提示文字
  119. Text(
  120. model?.listStyle?.searchCss?.text ?? '搜索更多优惠商品',
  121. style: TextStyle(fontSize: 14, color: HexColor.fromHex(model?.listStyle?.searchCss?.textColor ?? '#999999')),
  122. )
  123. ],
  124. ),
  125. ),
  126. ),
  127. );
  128. }
  129. }