Flutter 我如何放置一个条件语句,以便根据flifter中的用户类型验证脚手架中FloatingActionButton的视图?

Flutter 我如何放置一个条件语句,以便根据flifter中的用户类型验证脚手架中FloatingActionButton的视图?,flutter,dart,Flutter,Dart,我正在努力使用一个带有三元运算符和if语句的FloatingActionButton来验证一个FloatingActionButton return Scaffold( resizeToAvoidBottomPadding: false, key: key, appBar: AppBar( title: Text('profile list'), flexibleSpace: header(), ), body: FutureBuilder<List&l

我正在努力使用一个带有三元运算符和if语句的FloatingActionButton来验证一个FloatingActionButton

return Scaffold(
  resizeToAvoidBottomPadding: false,
  key: key,
  appBar: AppBar(
    title: Text('profile list'),
    flexibleSpace: header(),
  ),
  body: FutureBuilder<List<Leave>>(
    future: fetchLeave(http.Client()),
    builder: (context, snapshot) {
      if (snapshot.hasError) print(snapshot.error);
      return snapshot.hasData
          ? profileListView(leave: snapshot.data)         //using this class variable 
          : Center(child: CircularProgressIndicator());
    },
  ),
  floatingActionButton: new FloatingActionButton(
    child: Icon(Icons.add),
    onPressed: () {
      Navigator.of(context).push(
        MaterialPageRoute(
          builder: (context) => ProfileForm(),
        ),
      );
    },
  ),
);
但它调用的函数为NULL

请帮我解决这个错误

profileListView()
class ProfileListView扩展了无状态小部件{
final List leave;//获取此变量
constprofilelistview({Key-Key,this.leave}):super(Key:Key);
小部件构建(构建上下文){
//其他代码
}
}
profileListView().leave
为空,因为您创建了
profileListView
的新实例。 要获取浮动操作按钮中的
leave
列表,可以使用FutureBuilder包装整个脚手架,而不仅仅是其
主体
参数:

小部件构建(…){ 回归未来建设者( 未来:请假(…), 生成器:(上下文,快照)=>Scaffold( 正文:snapshot.hasData?..:CircularProgressIndicator(), floatingActionButton:snapshot.hasData&&snapshot.data[0]? 浮动操作按钮(…): 无效的 ), ); }
这样,您的主体和按钮将始终可以访问相同的同步状态。

profileListView到底是什么?小部件?请提供更多信息,因为我们不知道您的profileListView是什么。我假设主体中的快照数据为null,因此调用方[]在null上被调用。我已经提到了所需的类,并且在floatingActionButton中添加了条件之后,似乎显示了错误。
floatingActionButton:
      (profileListView().leave[0].userdetails.userType == "student")    //using the variable of another class
          ? new FloatingActionButton(
              //other codes
            )
          : new FloatingActionButton(
              //other codes
            ),
class ProfileListView extends StatelessWidget {
  final List<Leave> leave;                 //fetching this variable
   
  const ProfileListView({Key key, this.leave}) : super(key: key);
   Widget build(BuildContext context) {
   
     //other codes

   }
}