I’m doing a simple check in Flutter, where after authenticating, it should redirect to HomePage().
I debugged and after authentication authController.isAuth = true but it doesn’t refer to HomePage().
class AuthOrHomePage extends StatelessWidget {
const AuthOrHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
AuthController authController = Provider.of(context);
return FutureBuilder(
future: authController.tryAutoLogin(),
builder: (ctx, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (snapshot.error != null) {
return const Center(
child: Text('Ocorreu um erro!'),
);
} else {
if (authController.isAuth) {
return const HomePage();
} else {
return const InitPage();
}
}
},
);
}
}
Any idea what it could be?
2
Answers
In flutter, if you want to navigate from one screen to another you can use
Navigator
.For more : https://api.flutter.dev/flutter/widgets/Navigator-class.html#:~:text=In%20Flutter%20these%20elements%20are,pop.
Try this way,