I am getting an error. I wrote a code like this:
class MainDart extends StatefulWidget {
const MainDart({Key? key}) : super(key: key);
@override
State<MainDart> createState() => _MainDartState();
}
class _MainDartState extends State<MainDart> {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.dark,
theme: ThemeData(
appBarTheme: const AppBarTheme(
color: Color(0xFF27272A),
elevation: 0,
toolbarHeight: 65,
),
scaffoldBackgroundColor: Color(0xFF27272A),
),
home: StreamUser(),
);
}
}
StreamUser() {
FirebaseAuth.instance.authStateChanges().listen((User? user) {
if (user == null) {
return Get.offAll(const LoginPage());
} else {
return Get.offAll(const HomePage());
}
});
}
But I am getting this error:
How can I solve the problem?
CodePudding user response:
If you remove the return statements in your StreamUser() function that should solve it. problem is that that function is supposed to return a type of Void (the function declaration has no return type in front of it) but you are returning the Get.offAll functions which are of type Future.
StreamUser() {
FirebaseAuth.instance.authStateChanges().listen((User? user) {
if (user == null) {
Get.offAll(const LoginPage());
} else {
Get.offAll(const HomePage());
}
});
}
If you really want to return the values of the Get.offAll functions then you should use
Future<dynamic> StreamUser() {
FirebaseAuth.instance.authStateChanges().listen((User? user) {
if (user == null) {
return Get.offAll(const LoginPage());
} else {
return Get.offAll(const HomePage());
}
});
}