【发布时间】:2019-12-20 14:42:12
【问题描述】:
我试图设置隐藏小部件ListTile 如果SharedPreferences 获取空数据,我尝试使用Visibility 并且我收到这样的错误
类型“未来”不是类型“小部件”的子类型
我的Widget build(BuildContext context)
Widget build(BuildContext context) {
return new Drawer(
child: new ListView(
children: <Widget>[
new DrawerHeader(
child: new Text("Menu"),
decoration: new BoxDecoration(color: Colors.lightBlueAccent),
),
new ListTile(
title: new Text("Profile"),
onTap: () {
Navigator.pop(context);
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new ProfileScreen()));
},
),
new ListTile(
title: new Text("Proposal List"),
onTap: () {
visibleMethod();
},
),
//MY PROBLEM HERE
Visibility(
visible: true,
child: listTileAju()),
new ListTile(
title: new Text("Sign Out"),
onTap: () async {
SharedPreferences pref = await SharedPreferences.getInstance();
pref.remove("authorization");
pref.remove("is_login");
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (BuildContext ctx) => LoginPage()));
},
),
],
));
}
还有My Widget listTileAju()
listTileAju() async {
SharedPreferences pref = await SharedPreferences.getInstance();
setState(() {
roleAju = (pref.getStringList('role_aju') ?? 'Something Went Wrong');
});
if (roleAju != null) {
Visibility(
visible: true,
child: new ListTile(
title: new Text("Aju List"),
onTap: () {
Navigator.pop(context);
Navigator.push(context,
new MaterialPageRoute(builder: (context) => new AjuScreen()));
},
),
);
} else {
Visibility(
visible: false,
child: new ListTile(
title: new Text("Aju List"),
onTap: null,
),
);
}
}
如果 SharedPreferences 获取空数据,我希望小部件 ListTile 可以隐藏
【问题讨论】: