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

260 lines
9.2 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, model.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': // 右1图标
  46. rlt = _buildStyle1Widget(context);
  47. break;
  48. case 'search_2': // 无图标
  49. rlt = _buildStyle2Widget(context);
  50. break;
  51. case 'search_3': // 左1右1图标
  52. rlt = _buildStyle3Widget(context);
  53. break;
  54. case 'search_4': // 右按钮
  55. rlt = _buildStyle4Widget(context);
  56. break;
  57. default:
  58. rlt = Container();
  59. break;
  60. }
  61. return rlt;
  62. }
  63. /// 左1右1图标
  64. Widget _buildStyle3Widget(BuildContext context) {
  65. return Row(
  66. mainAxisAlignment: MainAxisAlignment.center,
  67. children: [
  68. GestureDetector(
  69. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  70. child: CachedNetworkImage(
  71. width: 30,
  72. height: 30,
  73. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  74. )),
  75. // 图标1
  76. SizedBox(width: 10),
  77. // 中间
  78. Expanded(
  79. child: GestureDetector(
  80. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  81. behavior: HitTestBehavior.opaque,
  82. child: Container(
  83. // height: 30,
  84. width: double.infinity,
  85. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 9),
  86. decoration: BoxDecoration(borderRadius: BorderRadius.circular(60 / 2), color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor)),
  87. child: Row(
  88. children: <Widget>[
  89. CachedNetworkImage(
  90. width: 15,
  91. height: 15,
  92. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  93. ),
  94. SizedBox(width: 4),
  95. Text(model?.listStyle?.searchCss?.text ?? '输入搜索内容,领券省钱', style: TextStyle(fontSize: 13, color: HexColor.fromHex(model?.listStyle?.searchCss?.textColor??"#FFFFFF")))
  96. ],
  97. ),
  98. ),
  99. )),
  100. SizedBox(width: 10),
  101. // 图标2
  102. GestureDetector(
  103. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  104. child: CachedNetworkImage(
  105. width: 30,
  106. height: 30,
  107. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  108. )),
  109. ],
  110. );
  111. }
  112. /// 左1右2图标
  113. Widget _buildStyle5Widget(BuildContext context) {
  114. return Row(
  115. mainAxisAlignment: MainAxisAlignment.center,
  116. children: [
  117. GestureDetector(
  118. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  119. child: CachedNetworkImage(
  120. width: 30,
  121. height: 30,
  122. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  123. )),
  124. // 图标1
  125. SizedBox(width: 10),
  126. // 中间
  127. Expanded(
  128. child: GestureDetector(
  129. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  130. behavior: HitTestBehavior.opaque,
  131. child: Container(
  132. // height: 30,
  133. width: double.infinity,
  134. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 9),
  135. decoration: BoxDecoration(borderRadius: BorderRadius.circular(60 / 2), color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor)),
  136. child: Row(
  137. children: <Widget>[
  138. CachedNetworkImage(
  139. width: 15,
  140. height: 15,
  141. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  142. ),
  143. SizedBox(width: 4),
  144. Text(model?.listStyle?.searchCss?.text ?? '输入搜索内容,领券省钱', style: TextStyle(fontSize: 13, color: HexColor.fromHex(model?.listStyle?.searchCss?.textColor??"#FFFFFF")))
  145. ],
  146. ),
  147. ),
  148. )),
  149. SizedBox(width: 10),
  150. // 图标2
  151. GestureDetector(
  152. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  153. child: CachedNetworkImage(
  154. width: 30,
  155. height: 30,
  156. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  157. )),
  158. SizedBox(width: 10),
  159. // 图标2
  160. GestureDetector(
  161. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  162. child: CachedNetworkImage(
  163. width: 30,
  164. height: 30,
  165. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  166. )),
  167. ],
  168. );
  169. }
  170. /// 右按钮
  171. Widget _buildStyle4Widget(BuildContext context) {
  172. return Container();
  173. }
  174. /// 右1图标
  175. Widget _buildStyle1Widget(BuildContext context) {
  176. return Row(
  177. children: <Widget>[
  178. Expanded(
  179. child: GestureDetector(
  180. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  181. behavior: HitTestBehavior.opaque,
  182. child: Container(
  183. // height: 30,
  184. width: double.infinity,
  185. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 9),
  186. decoration: BoxDecoration(borderRadius: BorderRadius.circular(60 / 2), color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor)),
  187. child: Row(
  188. children: <Widget>[
  189. CachedNetworkImage(
  190. width: 15,
  191. height: 15,
  192. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  193. ),
  194. SizedBox(width: 4),
  195. Text(model?.listStyle?.searchCss?.text ?? '输入搜索内容,领券省钱', style: TextStyle(fontSize: 13, color: HexColor.fromHex(model?.listStyle?.searchCss?.textColor??"#FFFFFF")))
  196. ],
  197. ),
  198. ),
  199. )),
  200. SizedBox(width: 10),
  201. GestureDetector(
  202. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  203. child: CachedNetworkImage(
  204. width: 30,
  205. height: 30,
  206. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  207. )),
  208. ],
  209. );
  210. }
  211. /// 无图标
  212. Widget _buildStyle2Widget(BuildContext context) {
  213. return GestureDetector(
  214. behavior: HitTestBehavior.opaque,
  215. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  216. child: Container(
  217. width: double.infinity,
  218. child: Container(
  219. width: double.infinity,
  220. decoration: BoxDecoration(
  221. borderRadius: BorderRadius.circular(40),
  222. color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor ?? '#F9F9F9'),
  223. ),
  224. padding: const EdgeInsets.symmetric(vertical: 6),
  225. child: Row(
  226. mainAxisAlignment: MainAxisAlignment.center,
  227. children: <Widget>[
  228. /// 搜索按钮
  229. CachedNetworkImage(
  230. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  231. height: 20,
  232. width: 20,
  233. ),
  234. const SizedBox(width: 7.5),
  235. /// 提示文字
  236. Text(
  237. model?.listStyle?.searchCss?.text ?? '搜索更多优惠商品',
  238. style: TextStyle(fontSize: 14, color: HexColor.fromHex(model?.listStyle?.searchCss?.textColor ?? '#999999')),
  239. )
  240. ],
  241. ),
  242. ),
  243. ),
  244. );
  245. }
  246. }