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

173 lines
5.0 KiB

  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.dart';
  4. import 'package:zhiying_base_widget/widgets/search/input/model/search_input_model.dart';
  5. import 'package:zhiying_base_widget/widgets/search/input/search_input_sk.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. import 'package:cached_network_image/cached_network_image.dart';
  8. ///
  9. /// 搜索页的搜索框
  10. ///
  11. class SearchInputWidget extends StatefulWidget {
  12. final Map<String, dynamic> data;
  13. SearchInputModel model;
  14. SearchInputWidget(this.data, {Key key}) : super(key: key) {
  15. try {
  16. model = SearchInputModel.fromJson(jsonDecode(data['data']));
  17. } catch (e) {
  18. Logger.error(e);
  19. }
  20. }
  21. @override
  22. _SearchInputWidgetState createState() => _SearchInputWidgetState();
  23. }
  24. class _SearchInputWidgetState extends State<SearchInputWidget> {
  25. /// 点击搜索按钮
  26. void _onSearchButtomClick() {}
  27. FocusNode _focusNode;
  28. TextEditingController _editingController;
  29. @override
  30. void didChangeDependencies() {
  31. super.didChangeDependencies();
  32. }
  33. @override
  34. void initState() {
  35. _focusNode = FocusNode();
  36. _editingController = TextEditingController();
  37. super.initState();
  38. }
  39. @override
  40. void dispose() {
  41. _focusNode?.unfocus();
  42. _focusNode?.dispose();
  43. _editingController?.dispose();
  44. super.dispose();
  45. }
  46. @override
  47. Widget build(BuildContext context) {
  48. return Visibility(
  49. visible: !EmptyUtil.isEmpty(widget?.model),
  50. replacement: SearchInputSkeleton(),
  51. child: _getMainWidget(widget?.model),
  52. );
  53. }
  54. /// 获取主视图
  55. Widget _getMainWidget(SearchInputModel model) {
  56. return Container(
  57. width: double.infinity,
  58. height: 32,
  59. margin: const EdgeInsets.only(
  60. left: 12.5,
  61. right: 12.5,
  62. ),
  63. decoration: BoxDecoration(
  64. borderRadius: BorderRadius.circular(25),
  65. color: HexColor.fromHex('#F9F9F9'),
  66. ),
  67. child: Row(
  68. children: <Widget>[
  69. /// 搜索icon
  70. _getSearchIconWidget(model),
  71. const SizedBox(width: 7.5),
  72. /// 搜索输入框
  73. Expanded(child: _getSearchInputWidget(model)),
  74. /// 搜索按钮
  75. _getSearchButtomWidget(model),
  76. ],
  77. ),
  78. );
  79. }
  80. /// 搜索icon
  81. Widget _getSearchIconWidget(SearchInputModel model) {
  82. return Container(
  83. height: double.infinity,
  84. width: 20,
  85. margin: const EdgeInsets.only(left: 12.5),
  86. padding: const EdgeInsets.symmetric(vertical: 6),
  87. child: CachedNetworkImage(
  88. imageUrl: model?.search_icon ?? '',
  89. ),
  90. );
  91. }
  92. /// 搜索输入框
  93. Widget _getSearchInputWidget(SearchInputModel model) {
  94. return Container(
  95. height: double.infinity,
  96. alignment: Alignment.centerLeft,
  97. // padding: const EdgeInsets.symmetric(vertical: 6),
  98. child: TextField(
  99. showCursor: true,
  100. cursorWidth: 1,
  101. style: TextStyle(fontSize: 14, color: HexColor.fromHex('#333333')),
  102. decoration: InputDecoration(
  103. filled: false,
  104. // focusColor: Colors.transparent,
  105. // fillColor: Colors.transparent,
  106. border: InputBorder.none,
  107. focusedBorder: InputBorder.none,
  108. focusedErrorBorder: InputBorder.none,
  109. errorBorder: InputBorder.none,
  110. disabledBorder: InputBorder.none,
  111. enabledBorder: InputBorder.none,
  112. hintText: '搜索更多优惠商品',
  113. hintStyle: TextStyle(color: HexColor.fromHex('#999999'), fontSize: 14),
  114. ),
  115. ),
  116. );
  117. }
  118. /// 搜索按钮
  119. Widget _getSearchButtomWidget(SearchInputModel model) {
  120. return GestureDetector(
  121. behavior: HitTestBehavior.opaque,
  122. onTap: () => _onSearchButtomClick(),
  123. child: Container(
  124. padding: const EdgeInsets.symmetric(horizontal: 17.5, vertical: 6),
  125. decoration: BoxDecoration(
  126. gradient: LinearGradient(colors: [HexColor.fromHex('#FD5E5E'), HexColor.fromHex('#FF0100')], begin: Alignment.centerLeft, end: Alignment.centerRight),
  127. borderRadius: BorderRadius.circular(30),
  128. ),
  129. child: Text(
  130. '搜索',
  131. style: TextStyle(color: HexColor.fromHex('#FFFFFF'), fontSize: 14),
  132. ),
  133. ),
  134. );
  135. }
  136. /// 【弃用】搜索按钮
  137. // Widget _getSearchButtomWidget() {
  138. // return Material(
  139. // child: Container(
  140. // decoration: BoxDecoration(
  141. // borderRadius: BorderRadius.only(topRight: Radius.circular(25), bottomRight: Radius.circular(25))
  142. // ),
  143. // height: double.infinity,
  144. // width: 63,
  145. // child: RaisedButton(
  146. // padding: const EdgeInsets.only(bottom: 6, top: 6, left: 17.5, right: 17.5),
  147. // shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular( 25)),
  148. // child: Text('搜索', style: TextStyle( fontSize: 14, color: HexColor.fromHex('#FFFFFF')),),
  149. // onPressed: ()=> _onSearchButtomClick(),
  150. // color: HexColor.fromHex('#FF0100'),
  151. // ),
  152. // ),
  153. // );
  154. // }
  155. }