[英]How to change button into textfield flutter
有多種方法可以做到這一點。 但是如果單擊按鈕,一種方法可以是跟蹤。 並添加一個 animatedSwitcher 在按鈕和文本字段之間切換
代碼看起來像這樣
class Example extends StatefulWidget {
const Example({Key? key}) : super(key: key);
@override
State<Example> createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
bool _isTextFieldShown = false;
@override
Widget build(BuildContext context) {
return AnimatedSwitcher(
duration: Duration(
milliseconds: 300,
),
child: _isTextFieldShown
? TextField()
: IconButton(
onPressed: () {
setState(() {
_isTextFieldShown = true;
});
},
icon: Icon(Icons.add)),
);
}
}
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.