import 'package:cofounderella/components/my_drawer.dart'; import 'package:cofounderella/components/user_tile.dart'; import 'package:cofounderella/services/auth/auth_service.dart'; import 'package:cofounderella/services/chat/chat_service.dart'; import 'package:flutter/material.dart'; import 'chat_page.dart'; class HomePage extends StatelessWidget { HomePage({super.key}); // chat and auth service final ChatService _chatService = ChatService(); final AuthService _authService = AuthService(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("Home"), // TODO appbar style: remove background and set elevation to 0 ? backgroundColor: Colors.transparent, foregroundColor: Colors.grey.shade800, elevation: 0, ), drawer: const MyDrawer(), body: _buildUserList(), ); } // build a list of users except for the current logged in user Widget _buildUserList() { return StreamBuilder( stream: _chatService.getUsersStream(), builder: (context, snapshot) { // error if (snapshot.hasError) { return const Text("Error"); } //loading if (snapshot.connectionState == ConnectionState.waiting) { return const Text("Loading.."); } // return list view return ListView( children: snapshot.data! .map( (userData) => _buildUserListItem(userData, context)) .toList(), ); }); } // build individual user list item Widget _buildUserListItem( Map userData, BuildContext context) { // display all users except current user if (userData["email"] != _authService.getCurrentUser()!.email) { return UserTile( text: userData["email"], onTap: () { // tapped on a user -> go to chat page // TODO Navigator.push( context, MaterialPageRoute( builder: (context) => ChatPage( receiverEmail: userData["email"], receiverID: userData["uid"], ), ), ); }, ); } else { return Container(); } } }