gpt4 book ai didi

flutter - 在 Flutter 中制作搜索栏

转载 作者:行者123 更新时间:2023-12-05 04:32:35 25 4
gpt4 key购买 nike

我做了一个搜索栏,看起来像这样

image

完整代码

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
),
],
)
],
),
);
}
}

我不知道如何具体解释,我可以在按下搜索框时以某种方式编码它导致另一个新页面吗?

enter image description here

或者有其他方法可以实现吗?如果可能,请逐步说明如何操作。

最佳答案

尝试使用 readOnly: true 并覆盖 onTap 方法以进入下一个搜索屏幕

TextField(
readOnly: true,
onTap: () {
//Go to the next screen
},
cursorColor: Colors.grey,
)

关于flutter - 在 Flutter 中制作搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71633268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com