十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
class SearchBar extends StatefulWidget {
SearchBar({Key? key, this.onChanged}) : super(key: key);
final ValueChanged? onChanged;
@override
_SearchBarState createState() =>_SearchBarState();
}
class _SearchBarState extends State{
final TextEditingController _textEditingController = TextEditingController();
List_models = [];
bool _showClear = false;
void _onChanged(String text) {
if (widget.onChanged != null) {
widget.onChanged!(text);
}
setState(() {
_showClear = text.isNotEmpty;
});
}
@override
Widget build(BuildContext context) {
return Container(
height: 84,
color: Colors.indigoAccent,
child: Column(
children: [
const SizedBox(
height: 40,
),
SizedBox(
height: 44,
child: Row(
children: [
Container(
width: 400,
height: 34,
margin: const EdgeInsets.only(left: 5, right: 5),
padding: const EdgeInsets.only(left: 5, right: 5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(6.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextField(
controller: _textEditingController,
cursorColor: Colors.green,
autofocus: true,
onChanged: _onChanged,
style: const TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.w300,
),
decoration: const InputDecoration(
contentPadding: EdgeInsets.only(left: 5,bottom: 10),
border:InputBorder.none,
hintText:'搜索',
),
),
),
if (_showClear) GestureDetector(
child: const Icon(
Icons.cancel,
size: 20,
color: Colors.grey,
),
onTap: () {
_textEditingController.clear();
setState(() {
_onChanged("");
});
},
)
],
),
), //圆角背景
GestureDetector(
child: const Text('取消'),
onTap: () {
},
),
],
),
),
],
),
);
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧