title: Null check operator used on a null value when using a static function
body: <p>I have a <code>static void</code> method that always returns a <code>null check error</code> , The same line of code works fine with other methods/ functions. I have no clue why this is happening.</p>
  <p>The configMaps.dart (global declaration)</p>
  <pre><code>User? currentFirebaseUser;
  </code></pre>
  <p>Next on main.dart</p>
  <pre><code>void main() async {
    WidgetsFlutterBinding.ensureInitialized();
  
    await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation&lt;
            AndroidFlutterLocalNotificationsPlugin&gt;()
        ?.createNotificationChannel(channel);
    await Firebase.initializeApp();
    currentFirebaseUser = FirebaseAuth.instance.currentUser;
    FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  
    await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
        alert: true, badge: true, sound: true);
    runApp(MyApp());
  }
  
  </code></pre>
  <p>HomeTabPages</p>
  <pre><code>class _HomeTabPageState extends State &lt; HomeTabPage &gt;
      with AutomaticKeepAliveClientMixin, OSMMixinObserver {
  
          isDriverAvailable = false; //check if user is online or offline, initially offline
  
  
          //under the widget tree
  
          RaisedButton(
              color: dsc.driverStatusClr,
              onPressed: () {
                  if (isDriverAvailable != true) {
                      isDriverAvailable = true;
                      makeDriverOnlineNow();
                      getLocationLiveUpdates();
                      displayToastMessage( //displays correct currentFirebaseUserId
                          currentFirebaseUser!.uid.toString(), context);
                      Provider.of &lt; AppData &gt; (context, listen: false)
                          .buttonOnline(Colors.green, &quot;Online&quot;);
  
                      // });
                      displayToastMessage(&quot;You are Online now&quot;, context);
                  } else {
                      Provider.of &lt; AppData &gt; (context, listen: false)
                          .buttonOnline(Colors.black, &quot;Offline&quot;);
                      driverOffline();
  
                      displayToastMessage(&quot;You are Offline now&quot;, context);
                      isDriverAvailable = false;
                  }
              },
              child: Padding(
                  padding: EdgeInsets.all(17),
                  child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                          Text(
                              dsc.driverStatusTxt,
                              style: TextStyle(
                                  fontSize: 20.0,
                                  fontWeight: FontWeight.bold,
                                  color: Colors.white),
                          ),
                          Icon(
                              Icons.phone_android,
                              color: Colors.white,
                              size: 26,
                          )
                      ],
                  ),
              ),
          )),
  
      void makeDriverOnlineNow() async {
          geo.Position position = await geo.Geolocator.getCurrentPosition(
              desiredAccuracy: geo.LocationAccuracy.high);
  
          await Geofire.initialize(&quot;availableDrivers&quot;);
        
          //there is no null check error here
          await Geofire.setLocation(
              currentFirebaseUser!.uid, position.latitude, position.longitude);
  
          await rideRequestRef!.set(&quot;searching&quot;);
          rideRequestRef!.onValue.listen((event) {});
      }
  
  void getLocationLiveUpdates() async {
      print(currentFirebaseUser.toString()); //I get the correct value till here but when it goes to call back its null
      return await BackgroundLocator.registerLocationUpdate(
          backgroundLocationCallBack,
          autoStop: false,
          // disposeCallback: backgroundLocationDisposeCallBack,
  
          androidSettings: AndroidSettings(
              accuracy: LocationAccuracy.NAVIGATION,
              interval: 5,
              distanceFilter: 0,
              client: LocationClient.google,
              androidNotificationSettings: AndroidNotificationSettings(
                  notificationChannelName: 'Location tracking',
                  notificationTitle: 'Start Location Tracking',
                  notificationMsg: 'Track location in background',
                  notificationBigMsg:
                  'Background location is on to keep the app up-tp-date with your location. This is required for main features to work properly when the app is not running.',
                  notificationIconColor: Colors.grey,
              )));
  }
  
  
  static void backgroundLocationCallBack(LocationDto location) async {
     
      print(&quot;from background location +${location.latitude}&quot;);
      
      //if (isDriverAvailable)
  
      //I get a null check used on a null value error here on , Even if I put the actual firebaseuser.id it will give a null,
      await Geofire.setLocation(
          currentFirebaseUser!.uid, location.latitude, location.longitude);
      print(&quot;from geofire +${location.latitude}&quot;);
      print(currentFirebaseUser.toString());
  }
  
  
  </code></pre>
  <p>The two methods here <code>makeDriverOnlineNow()</code> and <code>getLocationLiveUpdates()</code> both implement</p>
  <pre><code> await Geofire.setLocation(
          currentFirebaseUser!.uid, position.latitude, position.longitude);
  </code></pre>
  <p>For  <code>makeDriverOnlineNow()</code> there is no error but for <code>getLocationLiveUpdates()</code> there is a null check error used on a null value at <code>currentFirebaseUser!.uid</code></p>