[英]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.