我需要創建一個自定義顫振文本框,該文本框在未聚焦時顯示提示文本和文本框的標簽,如下所示

我怎樣才能做到這一點?
uj5u.com熱心網友回復:
您可以floatingLabelBehavior: FloatingLabelBehavior.always在輸入裝飾中使用
TextField(
decoration: InputDecoration(
labelText: "your lable",
labelStyle: TextStyle(fontSize: 20.0, height: 0.8),
hintText: 'this is hint',
floatingLabelBehavior: FloatingLabelBehavior.always // <-- use this
),
)
uj5u.com熱心網友回復:
你可以在這里找到檔案: https ://docs.flutter.dev/cookbook/forms/text-input
return Scaffold(
appBar: AppBar(
title: Text('Example of Texfield'),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
child: TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter something',
hintText: 'Enter a search term',
),
),
),
);
您還可以將 TextField 包裝在 Container 或 Sized Box 中,并在其中自定義您需要的所有內容。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/496447.html
