'error: The function can't be unconditionally invoked because it can be 'null'. with flutter
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:ourchat/screens/home/chat_screen.dart';
import 'package:ourchat/screens/welcome/welcome_screen.dart';
class LandingPage extends StatefulWidget{
@override
State<LandingPage> createState() => _LandingPageState();
}
class _LandingPageState extends State<LandingPage>{
late User _user;
@override
void initState(){
// TODO: implement initState
super.initState();
_checkUser();
}
@override
Widget build(BuildContext context) {
if(_user == null){
return WelcomeScreen();
}else{
return HomePage();
}
}
Future<void> _checkUser() async{
_user = await FirebaseAuth.instance.currentUser(); //=> ERROR
}
}
what should i do here? I also get an error when I put an exclamation mark, couldn't understand why. I specified where I got the error.Thanks for your help
Solution 1:[1]
Try FirebaseAuth.instance.currentUser without (), as this is not a function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Md. Kamrul Amin |
