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

146 lines
4.9 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 = Container();
  53. break;
  54. case 'search_4': // 右按钮
  55. rlt = Container();
  56. break;
  57. default:
  58. rlt = Container();
  59. break;
  60. }
  61. return rlt;
  62. }
  63. /// 右1图标
  64. Widget _buildStyle1Widget(BuildContext context) {
  65. return Row(
  66. children: <Widget>[
  67. Expanded(
  68. child: GestureDetector(
  69. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  70. behavior: HitTestBehavior.opaque,
  71. child: Container(
  72. // height: 30,
  73. width: double.infinity,
  74. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 9),
  75. decoration: BoxDecoration(borderRadius: BorderRadius.circular(60 / 2), color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor)),
  76. child: Row(
  77. children: <Widget>[
  78. CachedNetworkImage(
  79. width: 13,
  80. height: 13,
  81. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  82. ),
  83. SizedBox(width: 4),
  84. Text(model?.listStyle?.searchCss?.text ?? '输入搜索内容,领券省钱', style: TextStyle(fontSize: 13, color: HexColor.fromHex(model?.listStyle?.searchCss?.textColor??"#FFFFFF")))
  85. ],
  86. ),
  87. ),
  88. )),
  89. SizedBox(width: 10),
  90. GestureDetector(
  91. onTap: () => _onClickListener(context, model?.listStyle?.rightCss),
  92. child: CachedNetworkImage(
  93. width: 30,
  94. height: 30,
  95. imageUrl: model?.listStyle?.rightCss?.image ?? '',
  96. )),
  97. ],
  98. );
  99. }
  100. /// 无图标
  101. Widget _buildStyle2Widget(BuildContext context) {
  102. return GestureDetector(
  103. behavior: HitTestBehavior.opaque,
  104. onTap: () => _onClickListener(context, model?.listStyle?.searchCss),
  105. child: Container(
  106. width: double.infinity,
  107. child: Container(
  108. width: double.infinity,
  109. decoration: BoxDecoration(
  110. borderRadius: BorderRadius.circular(40),
  111. color: HexColor.fromHex(model?.listStyle?.searchCss?.bgColor ?? '#F9F9F9'),
  112. ),
  113. padding: const EdgeInsets.symmetric(vertical: 6),
  114. child: Row(
  115. mainAxisAlignment: MainAxisAlignment.center,
  116. children: <Widget>[
  117. /// 搜索按钮
  118. CachedNetworkImage(
  119. imageUrl: model?.listStyle?.searchCss?.image ?? '',
  120. height: 20,
  121. width: 20,
  122. ),
  123. const SizedBox(width: 7.5),
  124. /// 提示文字
  125. Text(
  126. model?.listStyle?.searchCss?.text ?? '搜索更多优惠商品',
  127. style: TextStyle(fontSize: 14, color: HexColor.fromHex(model?.listStyle?.searchCss?.textColor ?? '#999999')),
  128. )
  129. ],
  130. ),
  131. ),
  132. ),
  133. );
  134. }
  135. }