在 Flutter 中制作搜索栏
我制作了一个看起来像这样的搜索栏
这是完整的代码,
import 'package:flutter/material.dart';
class SearchInput extends StatefulWidget {
@override
State<SearchInput> createState() => _SearchInputState();
}
class _SearchInputState extends State<SearchInput> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 25, left: 25, right: 25),
child: Column(
children: [
Row(
children: [
Flexible(
flex: 1,
child: TextField(
cursorColor: Colors.grey,
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none
),
hintText: 'Search',
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 18
),
prefixIcon: Container(
padding: EdgeInsets.all(15),
child: Image.asset('assets/icons/search.png'),
width: 18,
)
),
),
),
Container(
margin: EdgeInsets.only (left: 10),
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(15)
),
child: Image.asset(
'assets/icons/filter.png'),
width: 25
),
],
)
],
),
);
}
}
我不知道如何具体解释它,当我按下搜索框时,我可以以某种方式对其进行编码吗?例如这个?
或者还有其他方法可以实现这一点吗?如果可能的话,请逐步解释如何做到这一点。
I made a search bar that looks like this
here's the full code
import 'package:flutter/material.dart';
class SearchInput extends StatefulWidget {
@override
State<SearchInput> createState() => _SearchInputState();
}
class _SearchInputState extends State<SearchInput> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 25, left: 25, right: 25),
child: Column(
children: [
Row(
children: [
Flexible(
flex: 1,
child: TextField(
cursorColor: Colors.grey,
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none
),
hintText: 'Search',
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 18
),
prefixIcon: Container(
padding: EdgeInsets.all(15),
child: Image.asset('assets/icons/search.png'),
width: 18,
)
),
),
),
Container(
margin: EdgeInsets.only (left: 10),
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(15)
),
child: Image.asset(
'assets/icons/filter.png'),
width: 25
),
],
)
],
),
);
}
}
I don't know how to explain it specifically, Can i somehow code it when i press the search box leads to another new page for example this?
Or is there another way to make it happen? And please explain it step by step on how to do it if it's possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
readOnly: true
并覆盖onTap
方法进入下一个搜索屏幕Try to use
readOnly: true
and overrideonTap
method to go next search screen