This is my auth.dart page to authenticate user. Now I want to go to Firebase collections 'users' table, if the value of the 'type' is 'Admin' navigate to AdminPage(), if it's 'Student' than navigate to StudentPage(). I have tried many thing but I couldn't find the answer.

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:modernlogintute/pages/admin_page.dart';
import 'package:modernlogintute/pages/location_page.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:modernlogintute/pages/login_page.dart';
import 'home_page.dart';
import 'login_or_register_page.dart';
class AuthPage extends StatelessWidget {
const AuthPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
// user is logged in
if (snapshot.hasData) {
return LocationPage();
}
// user is NOT logged in
else {
return LoginOrRegisterPage();
}
},
),
);
}
}
Instead of
return LocationPagedireclry , do something like code below. You may need to change it a bit according to your code.Or you can follow this video so you can fully understand what is going on : Tutorial on how to handle simple role base login