YSSearchView.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. class YSSearchView extends StatefulWidget {
  4. final ValueSetter postSearch;
  5. const YSSearchView({Key key, this.postSearch}) : super(key: key);
  6. @override
  7. _YSSearchViewState createState() => _YSSearchViewState();
  8. }
  9. class _YSSearchViewState extends State<YSSearchView> {
  10. TextEditingController _editingController = TextEditingController();
  11. @override
  12. Widget build(BuildContext context) {
  13. return Container(
  14. height: 40,
  15. decoration: BoxDecoration(
  16. color: Color(0xFFF1F1F1),
  17. borderRadius: BorderRadius.all(Radius.circular(50))
  18. ),
  19. margin: EdgeInsets.only(top: 5,bottom: 15,left: 15,right: 15),
  20. padding: EdgeInsets.only(left: 15,right: 15),
  21. child: CupertinoTextField(
  22. controller: _editingController,
  23. placeholder: '请输入关键字',
  24. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFFC8C9CC)),
  25. style: TextStyle(fontSize: 14,color: Color(0xFFC8C9CC)),
  26. decoration: BoxDecoration(color: Colors.transparent),
  27. padding: EdgeInsets.only(left: 5),
  28. prefix: Image.asset('lib/images/search_fy.png',height: 15,width: 15,),
  29. suffix: GestureDetector(
  30. onTap: (){
  31. _editingController.text = '';
  32. setState(() {});
  33. },
  34. child: Image.asset('lib/images/clear2_fy.png',height: 15,width: 15,),
  35. ),
  36. onSubmitted: (value){
  37. widget.postSearch(value);
  38. },
  39. textInputAction: TextInputAction.search,
  40. ),
  41. )
  42. ;
  43. }
  44. }
  45. class YSSearchView2 extends StatefulWidget {
  46. final ValueSetter postSearch;
  47. const YSSearchView2({Key key, this.postSearch}) : super(key: key);
  48. @override
  49. _YSSearchView2State createState() => _YSSearchView2State();
  50. }
  51. class _YSSearchView2State extends State<YSSearchView2> {
  52. TextEditingController _editingController = TextEditingController();
  53. @override
  54. void dispose() {
  55. _editingController.dispose();
  56. super.dispose();
  57. }
  58. @override
  59. Widget build(BuildContext context) {
  60. return CupertinoTextField(
  61. placeholder: '搜索卫生院、小区、村、社区',
  62. style: TextStyle(fontSize: 10,color: Color(0xFF444444)),
  63. padding: EdgeInsets.only(left: 5,right: 5),
  64. decoration: BoxDecoration(),
  65. prefix: Image.asset('lib/images/search_fy.png',height: 15,width: 15,),
  66. suffix: _editingController.text.isNotEmpty?GestureDetector(
  67. child: Image.asset('lib/images/clear2_fy.png',height: 15,width: 15,color: Colors.grey,),
  68. onTap: (){
  69. _editingController.text = '';
  70. setState(() {});
  71. },
  72. ):Container(height: 15,),
  73. textInputAction: TextInputAction.search,
  74. controller: _editingController,
  75. onSubmitted: (value){
  76. widget.postSearch(value);
  77. },
  78. onChanged: (value){
  79. setState(() {});
  80. },
  81. );
  82. }
  83. }