我正在尝试在 futurebuilder 中登录后进行导航。api 请求成功完成,但测试时导航出错。帮助我如何正确使用 futurebuilder。
child: ElevatedButton(
onPressed: () {
// Validate returns true if the form is valid, or false otherwise.
if (_mobileKey.currentState!.validate()) {
FutureBuilder<Loginuser>(
future: loginuser(mobileController.text.toString(),
passwordController.text.toString()),
builder: (context, snapshot) {
if (snapshot.hasData) {
context.go('/Home');
return Text(snapshot.data!.message);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
// By default, show a loading spinner.
return const CircularProgressIndicator();
},
);
}
context.go('/Home');
},
child: const Text('Submit')),
Run Code Online (Sandbox Code Playgroud)
我试过这个它不起作用。我使用“ go_router: ^5.2.4 ”进行导航