我的問題 我要搜索記錄頁面
我想要功能
我用 TextField 做了一個搜索欄,
我希望 TextField 中的 ontap 功能與啟動器 TextButton 一樣有效。
代碼
TextField(
onTap: () {},
decoration: InputDecoration(
hintText: "Please Input Data",
hintStyle: TextStyle(
fontFamily: 'Source Han Sans KR',
fontSize: 14,
color: const Color(0xffbcbcbc),
letterSpacing: -0.35000000000000003,
fontWeight: FontWeight.w300,
),
border: InputBorder.none,
prefixIcon: Icon(Icons.search)),
),
TextButton(
onPressed: () {
},
child: Text(
'Activate',
style: TextStyle(
fontFamily: 'Source Han Sans KR',
fontSize: 16,
color: const Color(0xff191919),
letterSpacing: -0.4,
),
softWrap: false,
))
uj5u.com熱心網友回復:
在此代碼中,如果 textField 有一些資料,則該按鈕將處于活動狀態。
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final textController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Row(
children: [
Expanded(
child: TextField(
onChanged: (value) {
setState(() {});
},
controller: textController,
decoration: InputDecoration(
hintText: "Please Input Data",
hintStyle: TextStyle(
fontFamily: 'Source Han Sans KR',
fontSize: 14,
color: Color(0xffbcbcbc),
letterSpacing: -0.35000000000000003,
fontWeight: FontWeight.w300,
),
border: InputBorder.none,
prefixIcon: Icon(Icons.search)),
),
),
TextButton(
onPressed: textController.text.isEmpty
? null
: () {
// your code here
},
child: Text(
'Activate',
style: TextStyle(
fontFamily: 'Source Han Sans KR',
fontSize: 16,
color: textController.text.isEmpty ? Colors.grey : Color(0xff191919),
letterSpacing: -0.4,
),
softWrap: false,
),
),
],
),
),
);
}
}
uj5u.com熱心網友回復:
您可能喜歡CupertinoSearchTextField()小部件。
您可以使用 aTextEditingController并將其用于
TextField(
controller: controller,
當你喜歡執行搜索時,獲取文本controller.text
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/534977.html
標籤:扑按钮文本域颤动的点按
