Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading