Untitled
part of '../pages.dart'; class HomePage extends StatefulWidget { const HomePage({super.key}); @override State<HomePage> createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { String? userId; late Future<Map<String, dynamic>> userData; final FirebaseService _auth = FirebaseService(); @override void initState() { super.initState(); User? user = _auth.currentUser; userId = user!.uid; userData = _auth.getUserData(userId!); } void _signOut() async { await _auth.signOut(); Navigator.pushReplacementNamed(context, '/sign-in'); } @override Widget build(BuildContext context) { return Scaffold( body: FutureBuilder<Map<String, dynamic>>( future: userData, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center( child: CircularProgressIndicator(), ); } if (snapshot.hasError) { return const Center(child: Text('Error fetching data')); } if (!snapshot.hasData || snapshot.data!.isEmpty) { return const Center(child: Text('User data not found')); } return Center( child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text('Welcome ${snapshot.data!['email']}'), Text('Name ${snapshot.data!['first_name']}'), Text('UID = $userId'), Text('Role ${snapshot.data!['role']}'), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.green), onPressed: () {}, child: Text( "Attedance", style: TextStyle(color: Colors.white), ), ), ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.amberAccent), onPressed: () { Navigator.pushNamed(context, '/note'); }, child: Text( "Notes", style: TextStyle(color: Colors.white), ), ), ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.blueAccent), onPressed: () {}, child: Text( "Profile", style: TextStyle(color: Colors.white), ), ), ], ), ElevatedButton( onPressed: () { _signOut(); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.red, ), child: Text( "Sign Out", style: TextStyle( color: colorWhite, ), ), ), ], ), ); }, ), ); } }
Leave a Comment