基础组件库
 
 
 
 
 

166 lines
5.7 KiB

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