how to browse screens in obx

Viewed 42

I'm in doubt about how to make it redirect to another screen when logging in with google, currently it's only displaying the elements on top of the same screen, how do I go to a new screen?

    class LoginPage extends StatelessWidget {
  final controller = Get.put(LoginController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.only(top: 50.0),
          ),
          Stack(
            children: [
              Image.asset(
                'assets/logov.png',
                height: 300,
                fit: BoxFit.fill,
              ),
              Padding(
                padding: const EdgeInsets.only(top: 355.0),
                child: Image.asset(
                  'assets/agua.png',
                  height: 300,
                  fit: BoxFit.fill,
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 500),
                child: Container(
                  **child: Obx(
                    () {
                      if (controller.googleAccount.value == null)
                        return buildLoginButton();
                      else
                        return Avatar(controller: controller,);
                    },
                  ),**
                  alignment: Alignment.bottomCenter,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
1 Answers

You can use default flutter navigation and navigate to the new page in your code

Also it's ok to remove the else since you have a return statement in the if

child: Obx(
            () {
                if (controller.googleAccount.value == null)
                   return buildLoginButton();

                   Navigator.push(context, 
                             MaterialPageRoute(builder: (_)=> 
                             Avatar(controller: controller,),)); // your home page
                   return SizedBox(); // just an empty box 
               },


Related