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{
  State<LandingPage> createState() => _LandingPageState();

class _LandingPageState extends State<LandingPage>{

  late User _user;

  void initState(){
    // TODO: implement initState

  Widget build(BuildContext context) {
    if(_user == null){
      return WelcomeScreen();
      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 :

Try FirebaseAuth.instance.currentUser without (), as this is not a function.

Leave a ReplyCancel reply