Integrate UserStateWrapper for user state management in group and home components; refactor profile and settings imports
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:travel_mate/components/error/error_content.dart';
|
||||
import 'package:travel_mate/components/group/chat_group_content.dart';
|
||||
import 'package:travel_mate/components/widgets/user_state_widget.dart';
|
||||
import '../../blocs/user/user_bloc.dart';
|
||||
import '../../blocs/user/user_state.dart' as user_state;
|
||||
import '../../blocs/group/group_bloc.dart';
|
||||
@@ -20,7 +21,7 @@ class _GroupContentState extends State<GroupContent> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
|
||||
// Charger immédiatement sans attendre le prochain frame
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_loadInitialData();
|
||||
@@ -30,7 +31,7 @@ class _GroupContentState extends State<GroupContent> {
|
||||
void _loadInitialData() {
|
||||
try {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
|
||||
|
||||
if (userState is user_state.UserLoaded) {
|
||||
final userId = userState.user.id;
|
||||
context.read<GroupBloc>().add(LoadGroupsByUserId(userId));
|
||||
@@ -44,36 +45,8 @@ class _GroupContentState extends State<GroupContent> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<UserBloc, user_state.UserState>(
|
||||
builder: (context, userState) {
|
||||
if (userState is user_state.UserLoading) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
if (userState is user_state.UserError) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error, size: 64, color: Colors.red),
|
||||
const SizedBox(height: 16),
|
||||
Text('Erreur: ${userState.message}'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (userState is! user_state.UserLoaded) {
|
||||
return const Scaffold(
|
||||
body: Center(child: Text('Utilisateur non connecté')),
|
||||
);
|
||||
}
|
||||
final user = userState.user;
|
||||
|
||||
return UserStateWrapper(
|
||||
builder: (context, user) {
|
||||
return BlocConsumer<GroupBloc, GroupState>(
|
||||
listener: (context, groupState) {
|
||||
if (groupState is GroupOperationSuccess) {
|
||||
@@ -94,9 +67,7 @@ class _GroupContentState extends State<GroupContent> {
|
||||
},
|
||||
builder: (context, groupState) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: _buildContent(groupState, user.id),
|
||||
),
|
||||
body: SafeArea(child: _buildContent(groupState, user.id)),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -123,11 +94,10 @@ class _GroupContentState extends State<GroupContent> {
|
||||
}
|
||||
|
||||
if (groupState is GroupsLoaded) {
|
||||
|
||||
if (groupState.groups.isEmpty) {
|
||||
return _buildEmptyState();
|
||||
}
|
||||
|
||||
|
||||
return _buildGroupsList(groupState.groups, userId);
|
||||
}
|
||||
|
||||
@@ -167,13 +137,13 @@ class _GroupContentState extends State<GroupContent> {
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
|
||||
...groups.map((group) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: _buildSimpleGroupCard(group),
|
||||
);
|
||||
})
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -183,7 +153,7 @@ class _GroupContentState extends State<GroupContent> {
|
||||
try {
|
||||
final colors = [Colors.blue, Colors.purple, Colors.green, Colors.orange];
|
||||
final color = colors[group.name.hashCode.abs() % colors.length];
|
||||
|
||||
|
||||
// Membres de manière simple
|
||||
String memberInfo = '${group.members.length} membre(s)';
|
||||
if (group.members.isNotEmpty) {
|
||||
@@ -193,7 +163,7 @@ class _GroupContentState extends State<GroupContent> {
|
||||
.join(', ');
|
||||
memberInfo += '\n$names';
|
||||
}
|
||||
|
||||
|
||||
return Card(
|
||||
elevation: 2,
|
||||
child: ListTile(
|
||||
@@ -232,7 +202,10 @@ class _GroupContentState extends State<GroupContent> {
|
||||
children: [
|
||||
Icon(Icons.forum_outlined, size: 80, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Aucun groupe', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
const Text(
|
||||
'Aucun groupe',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Les groupes sont créés automatiquement',
|
||||
@@ -245,7 +218,7 @@ class _GroupContentState extends State<GroupContent> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorState(String error, String userId, bool retry) {
|
||||
Widget _buildErrorState(String error, String userId, bool retry) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
if (retry) {
|
||||
@@ -283,21 +256,19 @@ class _GroupContentState extends State<GroupContent> {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
void _openGroupChat(Group group) {
|
||||
void _openGroupChat(Group group) {
|
||||
try {
|
||||
// Navigation vers la page de chat
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChatGroupContent(group: group),
|
||||
),
|
||||
MaterialPageRoute(builder: (context) => ChatGroupContent(group: group)),
|
||||
);
|
||||
} catch (e) {
|
||||
_buildErrorState(e.toString(), '', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user