Home > Back-end >  error: The function can't be unconditionally invoked because it can be 'null'. with f
error: The function can't be unconditionally invoked because it can be 'null'. with f

Time:05-25

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

CodePudding user response:

Use User? _user; instead of late User _user; on line number 6

CodePudding user response:

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

  • Related