class AppState extends State<App> {
int counter = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Center(
child: Text(if(counter = 0) {
return 'Hi';
} else {
return 'Go';
}),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
counter += 1;
name = 'by!';
});
},
答案 0 :(得分:1)
试试这个代码:
Text(counter==0?'hi':'go')