So I have a problem with my project regarding navigating/redirecting a user based on which collection he/she is present, either from Customers or Couriers. A user in a Customer collection can navigate to his/her respective dashboard, but if a user is from a Courier collection, I am stuck in a loading screen and it shows an error about the navigator.
Here is a snippet of the user type identification logic:
var a = await FirebaseFirestore.instance.collection('Customers').doc(user.uid).get();
if(a.exists){
print('Customer exists');
Navigator.pushNamed(context, '/dashboardLocation');
}
if(!a.exists){
print('Customer does not exist, maybe courier');
}
var b = await FirebaseFirestore.instance.collection('Couriers').doc(user.uid).get();
if(b.exists){
print('Courier exists');
Navigator.pushNamed(context, '/courierDashboard');
}
if(!b.exists){
print('Courier does not exist, maybe customer');
}
This is the error that I get:
E/flutter (19420): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
E/flutter (19420): #0 StatefulElement.state (package:flutter/src/widgets/framework.dart:4789:44)
E/flutter (19420): #1 Navigator.of (package:flutter/src/widgets/navigator.dart:2730:47)
E/flutter (19420): #2 Navigator.pushNamed (package:flutter/src/widgets/navigator.dart:1742:22)
E/flutter (19420): #3 _LoginScreenState.build.<anonymous closure> (package:proxpress/UI/login_screen.dart:143:47)
E/flutter (19420): <asynchronous suspension>
E/flutter (19420):
Thanks!