Jam
Jam

Reputation: 117

How do I render a widget based on a condition in flutter?

 Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(
      title: Text(MyApp.title),
      centerTitle: true,
    ),
    body: (()=>{
      if(!list){
        return Register();
      }
      else{
        return Homepage();
      }
    })
  );

My application fetches a list from local storage on init afterwards the next page to be rendered depends on whether the list is empty or not. Is there a way to determine which widget to render base on a condition?

Upvotes: 0

Views: 928

Answers (1)

Naveen Avidi
Naveen Avidi

Reputation: 3073

Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(
      title: Text(MyApp.title),
      centerTitle: true,
    ),
    body: list.isEmpty ? Register() : Homepage()
  );

Upvotes: 1

Related Questions