如何在颤振中进行条件渲染

时间:2021-02-07 06:49:18

标签: flutter dart

enter image description here


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!';
            });
          },

1 个答案:

答案 0 :(得分:1)

试试这个代码:

Text(counter==0?'hi':'go')