Add UserStateWrapper and ProfileImageService for user state management and profile image handling
This commit is contained in:
@@ -237,16 +237,16 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
? Colors.white.withValues(alpha: 0.2)
|
||||
: Colors.black.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
? Colors.white.withValues(alpha: 0.2)
|
||||
: Colors.black.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
@@ -267,7 +267,9 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: theme.colorScheme.outline.withOpacity(0.5)),
|
||||
border: Border.all(
|
||||
color: theme.colorScheme.outline.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -275,7 +277,7 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
Text(
|
||||
'Sélectionnez une catégorie',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.7),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/user/user_event.dart' as user_event;
|
||||
@@ -10,22 +11,8 @@ class ProfileContent extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<UserBloc, user_state.UserState>(
|
||||
builder: (context, state) {
|
||||
if (state is user_state.UserLoading) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (state is user_state.UserError) {
|
||||
return Center(child: Text('Erreur: ${state.message}'));
|
||||
}
|
||||
|
||||
if (state is! user_state.UserLoaded) {
|
||||
return Center(child: Text('Aucun utilisateur connecté'));
|
||||
}
|
||||
|
||||
final user = state.user;
|
||||
|
||||
return UserStateWrapper(
|
||||
builder: (context, user) {
|
||||
return Column(
|
||||
children: [
|
||||
// Section titre
|
||||
@@ -181,7 +168,10 @@ class ProfileContent extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _showChangePasswordDialog(BuildContext context, user_state.UserModel user) {
|
||||
void _showChangePasswordDialog(
|
||||
BuildContext context,
|
||||
user_state.UserModel user,
|
||||
) {
|
||||
final currentPasswordController = TextEditingController();
|
||||
final newPasswordController = TextEditingController();
|
||||
final confirmPasswordController = TextEditingController();
|
||||
@@ -210,7 +200,9 @@ class ProfileContent extends StatelessWidget {
|
||||
TextField(
|
||||
controller: confirmPasswordController,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(labelText: 'Confirmer le mot de passe'),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Confirmer le mot de passe',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -233,7 +225,8 @@ class ProfileContent extends StatelessWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPasswordController.text != confirmPasswordController.text) {
|
||||
if (newPasswordController.text !=
|
||||
confirmPasswordController.text) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Les mots de passe ne correspondent pas'),
|
||||
@@ -274,7 +267,10 @@ class ProfileContent extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteAccountDialog(BuildContext context, user_state.UserModel user) {
|
||||
void _showDeleteAccountDialog(
|
||||
BuildContext context,
|
||||
user_state.UserModel user,
|
||||
) {
|
||||
final passwordController = TextEditingController();
|
||||
final authService = AuthService();
|
||||
|
||||
|
||||
42
lib/components/widgets/user_state_widget.dart
Normal file
42
lib/components/widgets/user_state_widget.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../blocs/user/user_bloc.dart';
|
||||
import '../../blocs/user/user_state.dart' as user_state;
|
||||
|
||||
class UserStateWrapper extends StatelessWidget {
|
||||
final Widget Function(BuildContext context, dynamic user) builder;
|
||||
final Widget? loadingWidget;
|
||||
final Widget? errorWidget;
|
||||
final Widget? noUserWidget;
|
||||
|
||||
const UserStateWrapper({
|
||||
super.key,
|
||||
required this.builder,
|
||||
this.loadingWidget,
|
||||
this.errorWidget,
|
||||
this.noUserWidget,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<UserBloc, user_state.UserState>(
|
||||
builder: (context, state) {
|
||||
if (state is user_state.UserLoading) {
|
||||
return loadingWidget ??
|
||||
const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (state is user_state.UserError) {
|
||||
return errorWidget ?? Center(child: Text('Erreur: ${state.message}'));
|
||||
}
|
||||
|
||||
if (state is! user_state.UserLoaded) {
|
||||
return noUserWidget ??
|
||||
const Center(child: Text('Aucun utilisateur connecté.'));
|
||||
}
|
||||
|
||||
return builder(context, state.user);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user