Sumit
Sumit

Reputation: 570

how to do conditional rendering in flutter

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

Upvotes: 0

Views: 423

Answers (1)

Ali Mohammadzadeh
Ali Mohammadzadeh

Reputation: 686

try this code:

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

Upvotes: 1

Related Questions