小编Har*_* .S的帖子

Futurebuilder 内的导航

我正在尝试在 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 ”进行导航

routes flutter flutter-futurebuilder flutter-go-router

1
推荐指数
1
解决办法
1235
查看次数