homepage: removed placeholder user listing

master
Rafael 2024-06-07 18:55:33 +02:00
parent 896db0125b
commit 15a6556ac0
5 changed files with 60 additions and 128 deletions

View File

@ -1,6 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../pages/conversations_page.dart'; import '../pages/conversations_page.dart';
import '../pages/home_page.dart';
import '../pages/liked_users_page.dart'; import '../pages/liked_users_page.dart';
import '../pages/user_data_page.dart'; import '../pages/user_data_page.dart';
import '../pages/settings_page.dart'; import '../pages/settings_page.dart';
@ -45,13 +44,13 @@ class MyDrawer extends StatelessWidget {
onTap: () { onTap: () {
// pop the drawer // pop the drawer
Navigator.pop(context); Navigator.pop(context);
// Navigate to HomePage? // Optional: Navigate to HomePage
Navigator.push( /* Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) => HomePage(), builder: (BuildContext context) => HomePage(),
), ),
); );*/
}, },
), ),
), ),

View File

@ -15,7 +15,7 @@ class ConversationsPage extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Your Chat Contacts'), title: const Text('My Chat Contacts'),
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
), ),
body: _buildUserMatchesList(), body: _buildUserMatchesList(),

View File

@ -1,11 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../components/my_drawer.dart'; import '../components/my_drawer.dart';
import '../components/user_tile.dart';
import '../constants.dart';
import '../services/auth/auth_service.dart'; import '../services/auth/auth_service.dart';
import '../services/user_service.dart';
import 'chat_page.dart';
class HomePage extends StatelessWidget { class HomePage extends StatelessWidget {
HomePage({super.key}); HomePage({super.key});
@ -23,68 +19,58 @@ class HomePage extends StatelessWidget {
drawer: const MyDrawer(), drawer: const MyDrawer(),
// body: _buildUserList(), // body: _buildUserList(),
body: Center( body: Center(
child: SingleChildScrollView( child: AspectRatio(
child: Column( aspectRatio: 1,
children: [ child: LayoutBuilder(
AspectRatio( builder: (context, constraints) {
aspectRatio: 1, // Calculation of the tile size based on the spacing
child: LayoutBuilder( double size = constraints.biggest.shortestSide / 2 - 16;
builder: (context, constraints) { return GridView.count(
// Calculation of the tile size based on the spacing crossAxisCount: 2,
double size = constraints.biggest.shortestSide / 2 - 16; crossAxisSpacing: 16.0,
return GridView.count( mainAxisSpacing: 16.0,
crossAxisCount: 2, padding: const EdgeInsets.all(16.0),
crossAxisSpacing: 16.0, shrinkWrap: true,
mainAxisSpacing: 16.0, physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(16.0), children: [
shrinkWrap: true, _buildTile(
physics: const NeverScrollableScrollPhysics(), context,
children: [ 'Discover',
_buildTile( Icons.explore,
context, Colors.lightBlue.shade300,
'Discover', '/discover',
Icons.explore, size,
Colors.lightBlue.shade300, ),
'/discover', _buildTile(
size, context,
), 'View Profiles',
_buildTile( Icons.supervised_user_circle,
context, Colors.teal.shade300,
'View Profiles', '/favorites',
Icons.star, size,
Colors.teal.shade300, ),
'/favorites', _buildTile(
size, context,
), 'Chat',
_buildTile( Icons.chat,
context, Colors.indigo.shade300,
'Chat', '/chats',
Icons.chat, size,
Colors.indigo.shade300, ),
'/chats', _buildTile(
size, context,
), 'My Profile',
_buildTile( Icons.edit_note,
context, Colors.blueGrey.shade300,
'My Profile', '/profile',
Icons.person, size,
Colors.blueGrey.shade300, ),
'/profile', ],
size, );
), },
], ),
);
},
),
),
Container(
height: 400, // Adjust this height as needed
child: _buildUserList(),
),
],
), ),
), ),
),
); );
} }
@ -95,8 +81,6 @@ class HomePage extends StatelessWidget {
Navigator.pushNamed(context, route); Navigator.pushNamed(context, route);
}, },
child: Container( child: Container(
width: size,
height: size,
decoration: BoxDecoration( decoration: BoxDecoration(
color: color, color: color,
borderRadius: BorderRadius.circular(16.0), borderRadius: BorderRadius.circular(16.0),
@ -110,64 +94,13 @@ class HomePage extends StatelessWidget {
color: Colors.white, color: Colors.white,
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
Text(title, Text(
style: const TextStyle(color: Colors.white, fontSize: 20)), title,
style: const TextStyle(color: Colors.white, fontSize: 20),
),
], ],
), ),
), ),
); );
} }
// build a list of users except for the current logged in user
Widget _buildUserList() {
return StreamBuilder(
stream: UserService.getUsersStream(),
builder: (context, snapshot) {
// error
if (snapshot.hasError) {
return Text('Error: ${snapshot.error.toString()}');
}
//loading
if (snapshot.connectionState == ConnectionState.waiting) {
return const Text('Loading..');
}
// return list view
return ListView(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: snapshot.data!
.map<Widget>(
(userData) => _buildUserListItem(userData, context))
.toList(),
);
});
}
// build individual user list item
Widget _buildUserListItem(
Map<String, dynamic> userData, BuildContext context) {
// display all users except current user
if (userData[Constants.dbFieldUsersEmail] !=
_authService.getCurrentUser()!.email) {
return UserTile(
text: userData[Constants.dbFieldUsersEmail],
onTap: () {
// tapped on a user -> go to chat page
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatPage(
receiverEmail: userData[Constants.dbFieldUsersEmail],
receiverID: userData[Constants.dbFieldUsersID],
),
),
);
},
);
} else {
return Container();
}
}
} }

View File

@ -232,7 +232,7 @@ class LikedUsersPageState extends State<LikedUsersPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Favorite people'), title: const Text('My favored profiles'),
), ),
body: Column( body: Column(
children: [ children: [

View File

@ -193,7 +193,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('User Profile'), title: const Text('My Profile Information'),
), ),
body: isLoading body: isLoading
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())