如何根据颤振中的条件渲染小部件?

时间:2021-06-22 06:37:24

标签: flutter dart mobile widget render

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

我的应用程序在 init 上从本地存储中获取一个列表,然后下一个要呈现的页面取决于该列表是否为空。有没有办法根据条件确定要呈现的小部件?

1 个答案:

答案 0 :(得分:1)

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