My app has a public area, and an area where users must be authenticated, for example a page with a chat. At the lowest level I have my authenticationService, where I can check if a user is authenticated by checking for null in:
authenticationService.currentUser
When I updated this functionality for null safety, I declared this variable as:
User? _currentUser;
However, within the chat-components I also often have to access the user, and since I know a user must already be authenticated to access this area I use "!" like this a lot:
authenticationService.currentUser!
Additionally I use assert on some entry-points to catch errors at least during development:
assert(authenticationService.currentUser != null);
Is there a better way than to use "!" a lot in these areas and basically disable the null safety here and hope for the best?