【发布时间】:2021-11-13 21:37:03
【问题描述】:
我是 Flutter 的新手! 我想在单击和按钮“更改文本”时更改“文本”的内容 见以下代码:
void main() {
runApp(MaterialApp(home: MyHomePage()));
}
class MyHomePage extends StatelessWidget {
const MyHomePage({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Center(
child: Text("App demo",
style: TextStyle(color: Colors.yellow, fontSize: 40))),
),
body:Center(
child: Column(children: [
Text("Hello word !", key: Key("textKey")),
TextButton(child: Text("change Text"), onPressed: (){
/* **I want to change "Hello word!" to "Text has changed"** */
debugPrint("Change");
},),
],),
)
),
);
}
}
【问题讨论】:
-
这能回答你的问题吗? Flutter change text when button pressed