我正试图根据用户显示抽屉,并且我已将用户类型存储在共享首选项中。但当我打开抽屉时,在加载抽屉之前无法从sharedPreferences获取数据?
widget.userType == 'admin'
? ListTile(
leading: Icon(Icons.receipt),
title: Text("User Record"),
onTap: () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (BuildContext context) => UserRecord()),
(Route<dynamic> route) => route is UserRecord,
);
},
)
: Container(),
我确实找到了一种方法。但我不确定它是否正确。我使用了futureBuilder,并将future传递为:
pref.getString('userType');