import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class YSSearchView extends StatefulWidget {
  final ValueSetter postSearch;
  const YSSearchView({Key key, this.postSearch}) : super(key: key);

  @override
  _YSSearchViewState createState() => _YSSearchViewState();
}

class _YSSearchViewState extends State<YSSearchView> {
  TextEditingController _editingController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return  Container(
      height: 40,
      decoration: BoxDecoration(
        color: Color(0xFFF1F1F1),
        borderRadius: BorderRadius.all(Radius.circular(50))
      ),
      margin: EdgeInsets.only(top: 5,bottom: 15,left: 15,right: 15),
      padding: EdgeInsets.only(left: 15,right: 15),
      child: CupertinoTextField(
        controller: _editingController,
        placeholder: '请输入关键字',
        placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFFC8C9CC)),
        style: TextStyle(fontSize: 14,color: Color(0xFFC8C9CC)),
        decoration: BoxDecoration(color: Colors.transparent),
        padding: EdgeInsets.only(left: 5),
        prefix: Image.asset('lib/images/search_fy.png',height: 15,width: 15,),
        suffix: GestureDetector(
          onTap: (){
            _editingController.text = '';
            setState(() {});
          },
          child: Image.asset('lib/images/clear2_fy.png',height: 15,width: 15,),
        ),
        onSubmitted: (value){
          widget.postSearch(value);
        },
        textInputAction: TextInputAction.search,
      ),
    )
    ;
  }
}

class YSSearchView2 extends StatefulWidget {
  final ValueSetter postSearch;
  const YSSearchView2({Key key, this.postSearch}) : super(key: key);

  @override
  _YSSearchView2State createState() => _YSSearchView2State();
}

class _YSSearchView2State extends State<YSSearchView2> {
  TextEditingController _editingController = TextEditingController();
  @override
  void dispose() {
    _editingController.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return CupertinoTextField(
      placeholder: '搜索卫生院、小区、村、社区',
      style: TextStyle(fontSize: 10,color: Color(0xFF444444)),
      padding: EdgeInsets.only(left: 5,right: 5),
      decoration: BoxDecoration(),
      prefix: Image.asset('lib/images/search_fy.png',height: 15,width: 15,),
      suffix: _editingController.text.isNotEmpty?GestureDetector(
        child: Image.asset('lib/images/clear2_fy.png',height: 15,width: 15,color: Colors.grey,),
        onTap: (){
          _editingController.text = '';
          setState(() {});
        },
      ):Container(height: 15,),
      textInputAction: TextInputAction.search,
      controller: _editingController,
      onSubmitted: (value){
        widget.postSearch(value);
      },
      onChanged: (value){
        setState(() {});
      },
    );
  }
}
