我有一个根级别BlocListener
,它监听全局AuthBloc
的身份验证状态更改,并在用户退出时使用Navigator
返回登录页面。
如果HomePage
在AuthBloc
位于AuthenticatedState
中,则后代HomePage
小部件也会消耗该auth状态。但是,退出后,子UnauthenticatedState
会使用新的BlocListener
构建,而根class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
// assume AuthBloc has already been provided
return BlocBuilder<AuthBloc, AuthState>(
listener: (context, state) {
if (state is! AuthenticatedState) {
Navigator.pushNamed(context, '/login');
// ^--- I expect this to be called before HomePage gets UnauthenticatedState
}
},
child: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext) {
return BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
// state == Unauthenticated after signing out <------
}
);
}
}
才有机会导航回登录名。
parent->child
这是预期的行为,还是应该有保证的args_mkdir = 'echo '+admin.pw+' | su -c "mkdir -p '+dst4+' && chmod 755 '+dst4+' && cp -r '+\
source_file+' '+dst4+' && echo "'+comment+'" > '+dst4+'/readme_{}.txt'.format(getpass.getuser())+'" '+admin.name
try:
subprocess.call(args_mkdir, shell=True)
except Exception, e:
print(e)
sys.exit(1)
else:
mail(comment)
更新顺序?建议的处理方式是什么?
答案 0 :(得分:0)
添加条件,
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext) {
return BlocBuilder<AuthBloc, AuthState>(
condition: (AuthState previousState, AuthState currentState) => currentState is AuthenticatedState,
builder: (context, state) {
/// Build your home page screen here
}
);
}
}