title: Error : Null check operator used on a null value
body: <p>I'm getting <strong>'Null check operator used on a null value'</strong> on my user profile page.</p>
  <p>User Account Code</p>
  <pre><code>/*
  import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:firebase_auth/firebase_auth.dart';*/
  import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  
  import 'login.dart';
  
  class UserAcc extends StatefulWidget {
    const UserAcc({Key? key}) : super(key: key);
  
    @override
    State&lt;UserAcc&gt; createState() =&gt; _UserAccState();
  }
  
  class _UserAccState extends State&lt;UserAcc&gt; {
    String? name;
    final FirebaseAuth _auth = FirebaseAuth.instance;
    **final user = FirebaseAuth.instance.currentUser!;**
  
    Future&lt;void&gt; signOut() async {
      await _auth.signOut();
      Navigator.pushReplacement(
          context, MaterialPageRoute(builder: (context) =&gt; MyLogin()));
    }
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        extendBodyBehindAppBar: true,
        backgroundColor: Colors.white,
        body: Center(
          child: Container(
              height: 300,
              width: 300,
              child: Card(
                  elevation: 30.0,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(20),
                  ),
                  color: Colors.white,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(padding: EdgeInsets.only(left: 20.0)),
                      SizedBox(
                        height: 20.0,
                      ),
                      Row(
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 20.0),
                          ),
                          Icon(Icons.account_circle_rounded, color: Colors.black38, size: 40,),
                          Text(
                            &quot; User Details&quot;,
                            style: TextStyle(
                                color: Colors.black38,
                                letterSpacing: 2.0,
                                fontSize: 20.0,
                            fontWeight: FontWeight.bold),
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 20.0,
                      ),
                      Text(
                        **&quot; Name : &quot; + user.displayName!,**
                        style: TextStyle(
                            color: Colors.black38,
                            letterSpacing: 2.0,
                            fontSize: 20.0,
                            fontWeight: FontWeight.bold),
                      ),
                      SizedBox(
                        height: 20.0,
                      ),
                      Text(
                        **&quot; Email : &quot; + user.displayName!,**
                        style: const TextStyle(
                            color: Colors.black38,
                            letterSpacing: 2.0,
                            fontSize: 20.0,
                            fontWeight: FontWeight.bold),
                      ),
                      SizedBox(
                        height: 20.0,
                      ),
                      ElevatedButton(
                          onPressed: () {
                          signOut();
                        },
                        child: Text(&quot;Sign out&quot;),
                        style: ElevatedButton.styleFrom(
                            primary: Colors.pink,
                            fixedSize: const Size(100, 30),
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(50))),
                      ),
                    ],
  
                  ),
  
              ),
  
  
          ),
  
        ),
  
  
      );
  
    }
  }
  
  </code></pre>
  <p>Error Log</p>
  <blockquote>
  <p>The following _CastError was thrown building Builder:
  Null check operator used on a null value
  The relevant error-causing widget was: MaterialApp
  MaterialApp:file:///C:/Users/Debangi%20Bhaumik/AndroidStudioProjects/myapp/android/app/lib/<strong>main.dart</strong>:21:12</p>
  </blockquote>
  <p>Hence it says the error is in main.dart, i'm attaching the main.dart file</p>
  <pre><code>import 'package:firebase_auth/firebase_auth.dart';
  import 'package:firebase_core/firebase_core.dart';
  import 'package:flutter/material.dart';
  import 'login.dart';
  import 'signup.dart';
  import 'startuppage.dart';
  
  void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    runApp(MyApp());
  
  }
  class MyApp extends StatelessWidget {
    const MyApp({Key key}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        initialRoute: 'login', // It will direct route to login page
        routes: {
          'login': (context) =&gt; const MyLogin(),
          'signup': (context) =&gt; const Mysignup(),
        },
      );
  
  
  
    }
  }
  </code></pre>
  <p><strong>Mylogin() page :</strong></p>
  <pre><code>
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:flutter/material.dart';
  import 'startuppage.dart';
  
  class MyLogin extends StatefulWidget {
    const MyLogin({Key? key}) : super(key: key);
  
    @override
    State&lt;MyLogin&gt; createState() =&gt; _MyLoginState();
  }
  
  class _MyLoginState extends State&lt;MyLogin&gt; {
  
  
    //editing controller
    final TextEditingController emailController = TextEditingController();
    final TextEditingController passwordController = TextEditingController();
    int _success = 1 ;
    late String _userEmail = &quot;&quot;;
  
    final user = FirebaseAuth.instance.currentUser;
  
  
    Future SignIn() async {
  
      await FirebaseAuth.instance.signInWithEmailAndPassword(
          email: emailController.text.trim(),
          password: passwordController.text.trim()
      );
  
    }
  
  
    @override
    Widget build(BuildContext context) {
  
      return  Container(
        decoration:  const BoxDecoration(
          //color: Color(0xFFaac8ba),
          gradient: LinearGradient
            (begin: Alignment.bottomLeft,
            end: Alignment.bottomRight,
            colors: [
            Color(0xFFde6262),
              Color(0xFFffb88c)
            ]
          ),
        ),
        child : Scaffold(
          backgroundColor: Colors.transparent, //By default, in scaffold the bg color is white.
  
          body: Container(
                padding: const EdgeInsets.only(top: 130, left: 35, right: 0),
                child: SingleChildScrollView(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children:  [
                      const  Text(
                        &quot;Welcome Back\nTo Check-it.&quot;,
                        style:  TextStyle(
                          color: Colors.black,
                          fontSize: 30,
                          fontFamily: 'Montserrat',
                          letterSpacing: 3,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
  
                      const  SizedBox(
                        height: 50.0,
                      ),
                     TextField(
                        controller: emailController,
                        keyboardType: TextInputType.emailAddress,
                        decoration:  const InputDecoration(
                            hintText: &quot;Email&quot;,
                            prefixIcon: Icon(Icons.mail, color: Colors.black,)
                        ),
                      ),
                      const SizedBox(
                        height: 20.0,
                      ),
                       TextField(
                         controller:passwordController,
                        obscureText: true,
                        keyboardType: TextInputType.visiblePassword,
                        decoration:  const InputDecoration(
                            hintText: &quot;Password&quot;,
                            prefixIcon: Icon(Icons.lock, color: Colors.black,)
                        ),
                      ),
                      const  SizedBox(
                        height: 50.0,
                      ),
                      ElevatedButton(
                        onPressed: () async{
                         // _signIn();
                          SignIn();
                          Navigator.push(
                              context,
                            MaterialPageRoute(builder: (context) =&gt; const Imageslider()),
                          );
                        },
                        style: ButtonStyle(
                          backgroundColor: MaterialStateProperty.all&lt;Color&gt;(Colors.black12),
                        ),
                        child: const Text(&quot;Login&quot;,
                          style: TextStyle(
                              fontSize: 18,
                              color: Colors.black54),
                        ),
                      ),
                      const SizedBox(
                        height: 10.0,
                      ),
                      Container(
                        alignment: Alignment.bottomCenter,
                        child: Text(
                            _success == 1
                                ?''
                                : (
                                _success == 2
                                    ? 'Sign-in successful! '
                                    : 'Sign-in failed!'),
                            style: const TextStyle(
                              color: Colors.white70,
                            )
                        ),
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children:  [
                          TextButton(
                              onPressed: () {
                                Navigator.pushNamed(context,'signup');
                              },
                              child: const Text ('New User? Sign Up',
                                style : TextStyle(
                                  decoration: TextDecoration.underline,
                                  fontSize: 18,
                                  color: Colors.black45,
                                ),
                              )),
  
  
                        ],
  
                      ),
  
  
                    ],
  
                  ),
                ),
              ),
          ),
        );
  
  
    }
  }
  
  </code></pre>
  <p><strong>My Signup Code :</strong></p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:firebase_core/firebase_core.dart';
  import 'package:flutter/material.dart';
  
  
  import 'startuppage.dart';
  
  final FirebaseAuth _auth = FirebaseAuth.instance;
  
  class Mysignup extends StatefulWidget {
    const Mysignup({Key? key}) : super(key: key);
  
    @override
    State&lt;Mysignup&gt; createState() =&gt; _MysignupState();
  }
  
  class _MysignupState extends State&lt;Mysignup&gt; {
  
    Future&lt;FirebaseApp&gt; _initializeFirebase() async {
      FirebaseApp firebaseApp = await Firebase.initializeApp();
      return firebaseApp;
    }
  
    //editing controller
    final TextEditingController name = TextEditingController();
    final TextEditingController emailController = TextEditingController();
    final TextEditingController passwordController = TextEditingController();
    late bool _success;
    bool isLoading = false;
  
    Future&lt;User?&gt; _register(String name, String email, String password) async{
      FirebaseAuth _auth = FirebaseAuth.instance;
  
      FirebaseFirestore _firestore = FirebaseFirestore.instance;
      try {
        UserCredential userCrendetial =  await _auth.createUserWithEmailAndPassword(email: emailController.text, password: passwordController.text);
  
        print(&quot;Account created Succesfull&quot;);
  
        userCrendetial.user?.updateDisplayName(name);
  
  
        await _firestore.collection('users').doc(_auth.currentUser?.uid).set({
          &quot;name&quot;: name,
          &quot;email&quot;: email,
          &quot;uid&quot;: _auth.currentUser?.uid,
        });
  
        return userCrendetial.user;
      } catch (e) {
        print(e);
        return null;
      }
    }
  
  
  
  
    @override
    Widget build(BuildContext context) {
      return Container(
        decoration:  const BoxDecoration(
          gradient: LinearGradient
            (colors: [
            Color(0xFF02aab0),
            Color(0xFF00cdac)
          ],
          ),
        ),
        child : Scaffold(
          backgroundColor: Colors.transparent, //By default, in scaffold the bg color is white.
  
          body: Container(
            padding: const EdgeInsets.only(top: 150, left: 35, right: 35),
            child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children:  [
                  const Text(
                    &quot;Let's Create Together.&quot;,
                    style:  TextStyle(
                      color: Colors.black,
                      fontSize: 30,
                      letterSpacing: 3,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  const SizedBox(
                    height: 40.0,
                  ),
                  TextField(
                    controller:name,
                    keyboardType: TextInputType.name,
                    decoration:  const InputDecoration(
                        hintText: &quot;Name&quot;,
                        prefixIcon: Icon(Icons.account_circle_rounded, color: Colors.black,)
                    ),
                  ),
  
                  const SizedBox(
                    height: 20.0,
                  ),
                  TextField(
                    controller:emailController,
                    keyboardType: TextInputType.emailAddress,
                    decoration:  const InputDecoration(
                        hintText: &quot;Email&quot;,
                        prefixIcon: Icon(Icons.mail, color: Colors.black,)
                    ),
                  ),
                  const SizedBox(
                    height: 20.0,
                  ),
                  TextField(
                    controller:passwordController,
                    obscureText: true,
                    keyboardType: TextInputType.visiblePassword,
                    decoration:  const InputDecoration(
                        hintText: &quot;Password&quot;,
                        prefixIcon: Icon(Icons.lock, color: Colors.black,)
                    ),
                  ),
                  const SizedBox(
                    height: 80.0,
                  ),
                  ElevatedButton(
                    onPressed: () async{
                      if (name.text.isNotEmpty &amp;&amp;
                          emailController.text.isNotEmpty &amp;&amp;
                          passwordController.text.isNotEmpty) {
                        setState(() {
                          isLoading = true;
                        });
  
                       _register(name.text, emailController.text, passwordController.text).then((user) {
                          if (user == null) {
                            setState(() {
                              isLoading = false;
                            });
                            Navigator.push(
                                context, MaterialPageRoute(builder: (_) =&gt; Imageslider()));
                            print(&quot;Account Created Sucessful&quot;);
                          } else {
                            print(&quot;Login Failed&quot;);
                            setState(() {
                              isLoading = false;
                            });
                          }
                        });
                      } else {
  
                        print(&quot;Please enter all the fields&quot;);
                      }
                    },
                    style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.all&lt;Color&gt;(Colors.black12),
                    ),
                    child: const Text(&quot;Sign Up&quot;,
                      style: TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                          color: Colors.black54),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      );
  
  
    }
  }
  
  
  </code></pre>
  <p><em><strong>Stracktrace</strong></em></p>
  <blockquote>
  <p>======== Exception caught by widgets library ======================================================= The following _CastError was thrown building Builder: Null check operator used on a null value</p>
  <p>The relevant error-causing widget was:    MaterialApp
  MaterialApp:file:///C:/Users/Debangi%20Bhaumik/AndroidStudioProjects/myapp/android/app/lib/main.dart:21:12
  When the exception was thrown, this was the stack:
  #0      new _UserAccState (file:///C:/Users/Debangi%20Bhaumik/AndroidStudioProjects/myapp/android/app/lib/useracc.dart:22:49)
  #1      UserAcc.createState (file:///C:/Users/Debangi%20Bhaumik/AndroidStudioProjects/myapp/android/app/lib/useracc.dart:16:35)
  #2      new StatefulElement (package:flutter/src/widgets/framework.dart:4891:25)
  #3      StatefulWidget.createElement (package:flutter/src/widgets/framework.dart:758:38) ...     Normal
  element mounting (275 frames)
  #278    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3817:16)
  #279    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6350:36)
  #280    Element.updateChild (package:flutter/src/widgets/framework.dart:3551:18)
  #281    RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5883:32)
  #282    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6375:17)
  #283    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #284    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4832:16)
  #285    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4977:11)
  #286    Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
  #287    StatefulElement.update (package:flutter/src/widgets/framework.dart:5009:5)
  #288    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #289    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4832:16)
  #290    Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
  #291    ProxyElement.update (package:flutter/src/widgets/framework.dart:5154:5)
  #292    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #293    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4832:16)
  #294    Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
  #295    ProxyElement.update (package:flutter/src/widgets/framework.dart:5154:5)
  #296    _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:108:11)
  #297    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #298    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6222:14)
  #299    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #300    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4832:16)
  #301    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4977:11)
  #302    Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
  #303    StatefulElement.update (package:flutter/src/widgets/framework.dart:5009:5)
  #304    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #305    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6222:14)
  #306    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #307    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6222:14)
  #308    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #309    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4832:16)
  #310    Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
  #311    ProxyElement.update (package:flutter/src/widgets/framework.dart:5154:5)
  #312    Element.updateChild (package:flutter/src/widgets/framework.dart:3530:15)
  #313    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4832:16)
  #314    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4977:11)
  #315    Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
  #316    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2659:19)
  #317    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:891:21)
  #318    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:370:5)
  #319    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146:15)
  #320    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1083:9)
  #321    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:997:5)
  #325    _invoke (dart:ui/hooks.dart:151:10)
  #326    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
  #327    _drawFrame (dart:ui/hooks.dart:115:31) (elided 3 frames from dart:async)</p>
  </blockquote>
  <p>I'm a beginner at this, please help me. I'm stuck at this stage for days.Thank you in advance1</p>