在我的抽屉中,有两个操作,如果用户登录,它将显示用户信息,否则将弹出登录屏幕,因此我想在打开抽屉时调用setState,如下所示:
clickLeftMenu: (BuildContext mainContext) {
LoginInfo.checkLogin(mainContext).then((islogin) {
print(islogin.toString());
if (!islogin)
showLogin(mainContext, true);
else{
Scaffold.of(mainContext).openDrawer();
setState(() {
//I want to update the user login info for rebuild screen for show
loginInfo = LoginInfo.getInfo();
});
}
});
},
在抽屉中使用loginInfo对象显示用户信息:
ListTile(
leading: Icon(Icons.account_circle,
color: Theme.of(context).primaryColor,
size: setWidth(context, 8.0)),
title: Text(
loginInfo.name ?? '',
//loginInfo. != null ? loginInfo.email : '',
style: TextStyle(
fontSize: 20.0,
color: Theme.of(context).primaryColor,
),
),
subtitle: Text(
loginInfo.email ?? '',
style: TextStyle(
fontSize: 10.0,
//color: this.primaryColor,
),
),
),
但是当我打电话时失败了,显示以下错误:
setState() or markNeedsBuild() called when widget tree was locked.
This _ModalScope<dynamic> widget cannot be marked as needing to build because the framework is locked
我尝试了很多方法,但还是失败了,您有任何想法或其他方法可以做到吗?
谢谢!
答案 0 :(得分:0)
beaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().clear();
beaconManager
.getBeaconParsers()
.add(new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.setBackgroundBetweenScanPeriod(5000l);
beaconManager.setBackgroundScanPeriod(1000l);
beaconManager.setRegionStatePersistenceEnabled(false);
Region region = new Region("backgroundRegion",null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
BackgroundPowerSaver backgroundPowerSaver = new BackgroundPowerSaver(this);