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

team_input_widget.dart 6.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_base_widget/pages/team_page/model/team_style_model.dart';
  3. import 'package:cached_network_image/cached_network_image.dart';
  4. import 'package:zhiying_base_widget/pages/team_page/notifier/team_page_notifier.dart';
  5. import 'package:zhiying_comm/zhiying_comm.dart';
  6. import 'package:provider/provider.dart';
  7. class TeamInputWidget extends StatefulWidget {
  8. TeamStyleModel styleModel;
  9. TabController tabController;
  10. TeamInputWidget(this.styleModel, this.tabController);
  11. @override
  12. _TeamInputWidgetState createState() => _TeamInputWidgetState();
  13. }
  14. class _TeamInputWidgetState extends State<TeamInputWidget> {
  15. TextEditingController _controller;
  16. FocusNode _focusNode;
  17. bool _showCancel = false;
  18. /// 搜索方法
  19. void _onSearchClick() {
  20. String text = _controller?.text?.toString()?.trim();
  21. if (!EmptyUtil.isEmpty(text) && text.length > 0) {
  22. widget?.tabController?.index = 0;
  23. Provider.of<TeamPageNotifier>(context, listen: false).searchReset(text);
  24. }
  25. }
  26. /// 点击取消输入
  27. void _cancel() {
  28. _controller?.clear();
  29. }
  30. void _onChange(text) {
  31. if (!EmptyUtil.isEmpty(text)) {
  32. if (!_showCancel) {
  33. setState(() {
  34. _showCancel = true;
  35. });
  36. }
  37. } else {
  38. if (_showCancel) {
  39. setState(() {
  40. _showCancel = false;
  41. });
  42. }
  43. }
  44. }
  45. @override
  46. void initState() {
  47. _controller = TextEditingController();
  48. _focusNode = FocusNode();
  49. super.initState();
  50. }
  51. @override
  52. void didChangeDependencies() {
  53. super.didChangeDependencies();
  54. }
  55. @override
  56. void dispose() {
  57. _focusNode?.unfocus();
  58. _focusNode?.dispose();
  59. _controller?.dispose();
  60. super.dispose();
  61. }
  62. @override
  63. void deactivate() {
  64. super.deactivate();
  65. _focusNode?.unfocus();
  66. }
  67. @override
  68. Widget build(BuildContext context) {
  69. return Container(
  70. width: double.infinity,
  71. height: double.infinity,
  72. padding: const EdgeInsets.only(top: 10, left: 12.5, right: 12.5),
  73. color: Colors.white,
  74. child: Row(
  75. children: <Widget>[
  76. /// 输入框
  77. Expanded(
  78. child: Container(
  79. height: 24,
  80. decoration: BoxDecoration(
  81. borderRadius: BorderRadius.circular(30),
  82. color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerInputBgColor ?? '#F7F7F7'),
  83. ),
  84. // padding: const EdgeInsets.only(top: 5, bottom: 4.5, left: 7.5, right: 7.5),
  85. width: double.infinity,
  86. child: Row(
  87. children: <Widget>[
  88. // Container(width: 11.5, height: 11.5, color: Colors.red,),
  89. /// 查询图标
  90. Padding(
  91. padding: const EdgeInsets.only(top: 5, bottom: 4.5, left: 7.5),
  92. child: CachedNetworkImage(
  93. imageUrl: widget?.styleModel?.searchBarLeftIcon,
  94. width: 11.5,
  95. )),
  96. Expanded(
  97. child: Container(
  98. padding: const EdgeInsets.only(top: 5, bottom: 4.5),
  99. color: Colors.transparent,
  100. child: TextField(
  101. controller: _controller,
  102. focusNode: _focusNode,
  103. onChanged: _onChange,
  104. onSubmitted: (text) => _onSearchClick(),
  105. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerInputColor ?? '#000000'), textBaseline: TextBaseline.alphabetic),
  106. decoration: InputDecoration(
  107. focusedBorder: InputBorder.none,
  108. border: InputBorder.none,
  109. focusedErrorBorder: InputBorder.none,
  110. errorBorder: InputBorder.none,
  111. disabledBorder: InputBorder.none,
  112. enabledBorder: InputBorder.none,
  113. filled: true,
  114. isDense: true,
  115. contentPadding: const EdgeInsets.only(left: 6, bottom: 0, top: 0, right: 0),
  116. fillColor: Colors.transparent,
  117. hintStyle:
  118. TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.searchBarHideTextColor ?? '#999999'), textBaseline: TextBaseline.alphabetic),
  119. hintText: widget?.styleModel?.searchBarHideText ?? '输入需搜索的手机号/昵称',
  120. ),
  121. ),
  122. ),
  123. ),
  124. // Container(width: 15, height: 15, color: Colors.red,)
  125. /// 关闭按钮
  126. Visibility(
  127. visible: _showCancel,
  128. child: GestureDetector(
  129. behavior: HitTestBehavior.opaque,
  130. onTap: () => _cancel(),
  131. child: Padding(
  132. padding: const EdgeInsets.only(top: 5, bottom: 4.5, right: 7.5),
  133. child: CachedNetworkImage(
  134. imageUrl: widget?.styleModel?.searchBarRightIcon,
  135. width: 11.5,
  136. ),
  137. )),
  138. ),
  139. ],
  140. ),
  141. ),
  142. ),
  143. const SizedBox(width: 8),
  144. /// 确定按钮
  145. GestureDetector(
  146. behavior: HitTestBehavior.opaque,
  147. onTap: () => _onSearchClick(),
  148. child: Container(
  149. height: double.infinity,
  150. alignment: Alignment.center,
  151. decoration: BoxDecoration(borderRadius: BorderRadius.circular(30), color: HexColor.fromHex(widget?.styleModel?.searchBarBtnBgColor ?? '#FF4242')),
  152. padding: const EdgeInsets.only(left: 15, right: 15, ),
  153. child: Text(
  154. widget?.styleModel?.searchBarBtnText ?? '搜索',
  155. style: TextStyle(color: HexColor.fromHex(widget?.styleModel?.searchBarBtnTextColor ?? '#FFFFFF'), fontSize: 11),
  156. ),
  157. ),
  158. )
  159. ],
  160. ),
  161. );
  162. }
  163. }