2025-08-02 03:42:56 +02:00
|
|
|
|
import 'package:flutter/material.dart';
|
2025-08-02 04:48:34 +02:00
|
|
|
|
import 'package:provider/provider.dart';
|
2025-08-02 05:00:44 +02:00
|
|
|
|
import '../services/network_group_service.dart';
|
|
|
|
|
import '../widgets/network_demo_widget.dart';
|
2025-08-02 03:42:56 +02:00
|
|
|
|
|
2025-08-02 04:16:15 +02:00
|
|
|
|
class GroupPage extends StatefulWidget {
|
2025-08-02 03:42:56 +02:00
|
|
|
|
const GroupPage({super.key});
|
|
|
|
|
|
2025-08-02 04:16:15 +02:00
|
|
|
|
@override
|
|
|
|
|
State<GroupPage> createState() => _GroupPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _GroupPageState extends State<GroupPage> {
|
2025-08-02 03:42:56 +02:00
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-08-02 05:00:44 +02:00
|
|
|
|
return Consumer<NetworkGroupService>(
|
|
|
|
|
builder: (context, networkService, child) {
|
|
|
|
|
final isConnected = networkService.isConnectedToWifi;
|
|
|
|
|
final networkName = networkService.currentNetworkName;
|
|
|
|
|
final currentUser = networkService.currentUser;
|
|
|
|
|
final networkUsers = networkService.networkUsers;
|
|
|
|
|
final onlineCount = networkService.onlineUsersCount;
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
color: const Color(0xFF121212),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(20.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
// WiFi Connection Status Card
|
|
|
|
|
Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: isConnected
|
|
|
|
|
? const Color(0xFF22C55E).withOpacity(0.1)
|
|
|
|
|
: const Color(0xFFEF4444).withOpacity(0.1),
|
|
|
|
|
borderRadius: BorderRadius.circular(15),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: isConnected
|
2025-08-02 04:16:15 +02:00
|
|
|
|
? const Color(0xFF22C55E)
|
|
|
|
|
: const Color(0xFFEF4444),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
width: 1,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
isConnected ? Icons.wifi : Icons.wifi_off,
|
|
|
|
|
size: 40,
|
|
|
|
|
color: isConnected
|
|
|
|
|
? const Color(0xFF22C55E)
|
|
|
|
|
: const Color(0xFFEF4444),
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
Text(
|
|
|
|
|
isConnected
|
|
|
|
|
? '<EFBFBD> Connected to $networkName'
|
|
|
|
|
: '❌ Not connected to WiFi',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: isConnected
|
|
|
|
|
? const Color(0xFF22C55E)
|
|
|
|
|
: const Color(0xFFEF4444),
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
|
Text(
|
|
|
|
|
isConnected
|
|
|
|
|
? 'You can now vote and suggest music with others on this network!'
|
|
|
|
|
: 'Please connect to WiFi to join the group session',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
fontSize: 14,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
|
|
|
|
if (isConnected && networkService.localIpAddress.isNotEmpty) ...[
|
|
|
|
|
const SizedBox(height: 8),
|
2025-08-02 04:16:15 +02:00
|
|
|
|
Text(
|
2025-08-02 05:00:44 +02:00
|
|
|
|
'IP: ${networkService.localIpAddress}',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.grey,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
fontSize: 12,
|
2025-08-02 05:00:44 +02:00
|
|
|
|
fontFamily: 'monospace',
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-08-02 05:00:44 +02:00
|
|
|
|
],
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
|
|
|
|
|
const SizedBox(height: 25),
|
|
|
|
|
|
|
|
|
|
// Current User Info Section
|
2025-08-02 04:16:15 +02:00
|
|
|
|
Container(
|
2025-08-02 05:00:44 +02:00
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: const EdgeInsets.all(18),
|
2025-08-02 04:16:15 +02:00
|
|
|
|
decoration: BoxDecoration(
|
2025-08-02 05:00:44 +02:00
|
|
|
|
color: const Color(0xFF1E1E1E),
|
2025-08-02 04:16:15 +02:00
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
CircleAvatar(
|
|
|
|
|
radius: 25,
|
|
|
|
|
backgroundColor: const Color(0xFF6366F1),
|
|
|
|
|
child: Text(
|
|
|
|
|
currentUser.name.substring(0, 1),
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 15),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
children: [
|
2025-08-02 05:00:44 +02:00
|
|
|
|
Text(
|
|
|
|
|
currentUser.name,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
Text(
|
|
|
|
|
'Active since ${_formatDuration(DateTime.now().difference(currentUser.joinedAt))} ago',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
fontSize: 12,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFF6366F1).withOpacity(0.2),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.how_to_vote,
|
|
|
|
|
color: Color(0xFF6366F1),
|
|
|
|
|
size: 14,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Text(
|
|
|
|
|
'${currentUser.votes} votes',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Color(0xFF6366F1),
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-08-02 04:16:15 +02:00
|
|
|
|
],
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
const SizedBox(height: 25),
|
|
|
|
|
|
|
|
|
|
// Demo Widget
|
|
|
|
|
NetworkDemoWidget(networkService: networkService),
|
|
|
|
|
|
|
|
|
|
// Network Users Section
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
const Text(
|
|
|
|
|
'Network Users',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFF6366F1).withOpacity(0.2),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
'$onlineCount online',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Color(0xFF6366F1),
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
const SizedBox(height: 15),
|
|
|
|
|
|
|
|
|
|
// Users List
|
|
|
|
|
Expanded(
|
|
|
|
|
child: isConnected
|
|
|
|
|
? networkUsers.isEmpty
|
|
|
|
|
? const Center(
|
2025-08-02 04:16:15 +02:00
|
|
|
|
child: Column(
|
2025-08-02 05:00:44 +02:00
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
children: [
|
2025-08-02 05:00:44 +02:00
|
|
|
|
Icon(
|
|
|
|
|
Icons.search,
|
|
|
|
|
size: 48,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 16),
|
2025-08-02 04:16:15 +02:00
|
|
|
|
Text(
|
2025-08-02 05:00:44 +02:00
|
|
|
|
'Searching for other users...',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.grey,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
SizedBox(height: 8),
|
2025-08-02 04:16:15 +02:00
|
|
|
|
Text(
|
2025-08-02 05:00:44 +02:00
|
|
|
|
'Make sure others are connected to the same WiFi network',
|
|
|
|
|
style: TextStyle(
|
2025-08-02 04:16:15 +02:00
|
|
|
|
color: Colors.grey,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
textAlign: TextAlign.center,
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
)
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
itemCount: networkUsers.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final user = networkUsers[index];
|
|
|
|
|
final isCurrentUser = user.id == currentUser.id;
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
margin: const EdgeInsets.only(bottom: 10),
|
|
|
|
|
padding: const EdgeInsets.all(15),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: isCurrentUser
|
|
|
|
|
? const Color(0xFF6366F1).withOpacity(0.1)
|
|
|
|
|
: const Color(0xFF1E1E1E),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: isCurrentUser
|
|
|
|
|
? Border.all(color: const Color(0xFF6366F1), width: 1)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Stack(
|
|
|
|
|
children: [
|
|
|
|
|
CircleAvatar(
|
|
|
|
|
radius: 20,
|
|
|
|
|
backgroundColor: isCurrentUser
|
|
|
|
|
? const Color(0xFF6366F1)
|
|
|
|
|
: const Color(0xFF4B5563),
|
|
|
|
|
child: Text(
|
|
|
|
|
user.name.substring(0, 1),
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
if (user.isOnline)
|
|
|
|
|
Positioned(
|
|
|
|
|
right: 0,
|
|
|
|
|
bottom: 0,
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 12,
|
|
|
|
|
height: 12,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFF22C55E),
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
border: Border.all(color: const Color(0xFF121212), width: 2),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 15),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
user.name,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
if (isCurrentUser) ...[
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFF6366F1),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
child: const Text(
|
|
|
|
|
'You',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Joined ${_formatDuration(DateTime.now().difference(user.joinedAt))} ago',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
if (!user.isOnline) ...[
|
|
|
|
|
const Text(
|
|
|
|
|
' • ',
|
|
|
|
|
style: TextStyle(color: Colors.grey, fontSize: 12),
|
|
|
|
|
),
|
|
|
|
|
const Text(
|
|
|
|
|
'Offline',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
if (user.ipAddress.isNotEmpty) ...[
|
|
|
|
|
const SizedBox(height: 2),
|
|
|
|
|
Text(
|
|
|
|
|
'IP: ${user.ipAddress}',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFF6366F1).withOpacity(0.2),
|
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
'${user.votes} votes',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Color(0xFF6366F1),
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: const Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.wifi_off,
|
|
|
|
|
size: 48,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 16),
|
|
|
|
|
Text(
|
|
|
|
|
'Connect to WiFi to join a group session',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Bottom Action Buttons
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ElevatedButton.icon(
|
|
|
|
|
onPressed: isConnected ? () async {
|
|
|
|
|
// Refresh network discovery
|
|
|
|
|
await networkService.refreshNetwork();
|
|
|
|
|
if (mounted) {
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
const SnackBar(
|
|
|
|
|
content: Text('Network refreshed! ✓'),
|
|
|
|
|
backgroundColor: Color(0xFF22C55E),
|
|
|
|
|
duration: Duration(seconds: 2),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} : null,
|
|
|
|
|
icon: const Icon(Icons.refresh),
|
|
|
|
|
label: const Text('Refresh Network'),
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
backgroundColor: const Color(0xFF6366F1),
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
2025-08-02 04:16:15 +02:00
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
],
|
2025-08-02 04:16:15 +02:00
|
|
|
|
),
|
|
|
|
|
],
|
2025-08-02 03:42:56 +02:00
|
|
|
|
),
|
2025-08-02 05:00:44 +02:00
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-08-02 03:42:56 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
2025-08-02 05:00:44 +02:00
|
|
|
|
|
|
|
|
|
String _formatDuration(Duration duration) {
|
|
|
|
|
if (duration.inMinutes < 1) {
|
|
|
|
|
return 'less than a minute';
|
|
|
|
|
} else if (duration.inMinutes < 60) {
|
|
|
|
|
return '${duration.inMinutes} minute${duration.inMinutes == 1 ? '' : 's'}';
|
|
|
|
|
} else {
|
|
|
|
|
final hours = duration.inHours;
|
|
|
|
|
final minutes = duration.inMinutes % 60;
|
|
|
|
|
if (minutes == 0) {
|
|
|
|
|
return '$hours hour${hours == 1 ? '' : 's'}';
|
|
|
|
|
} else {
|
|
|
|
|
return '$hours hour${hours == 1 ? '' : 's'} $minutes minute${minutes == 1 ? '' : 's'}';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|