如果我直接调用Navigator.pushname方法,我会收到一条消息,告诉我不要跨异步间隙使用‘BuildContext’.我不知道如何解决这个问题并移动到下一个屏幕. 这就是代码
color: Colors.blueAccent,
title: 'Register',
onPressed: () async {
try {
final newUser = await _auth.createUserWithEmailAndPassword(
email: email, password: password);
if (newUser.user != null) {
await Future.delayed(Duration.zero);
Navigator.of(context).pushNamed(ChatScreen.id);
}
} catch (e) {
print(e);
}
},
),
```