Dropzone OK et refactor page event_add
This commit is contained in:
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:em2rp/models/user_model.dart';
|
||||
import 'package:em2rp/utils/colors.dart';
|
||||
|
||||
class UserCard extends StatelessWidget {
|
||||
class UserCard extends StatefulWidget {
|
||||
final UserModel user;
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onDelete;
|
||||
@ -16,6 +16,66 @@ class UserCard extends StatelessWidget {
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
@override
|
||||
State<UserCard> createState() => _UserCardState();
|
||||
}
|
||||
|
||||
class _UserCardState extends State<UserCard> {
|
||||
ImageProvider? _profileImage;
|
||||
String? _lastUrl;
|
||||
bool _isLoadingImage = false;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(UserCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.user.profilePhotoUrl != widget.user.profilePhotoUrl) {
|
||||
_loadProfileImage();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadProfileImage();
|
||||
}
|
||||
|
||||
void _loadProfileImage() {
|
||||
final url = widget.user.profilePhotoUrl;
|
||||
if (url.isNotEmpty) {
|
||||
setState(() {
|
||||
_isLoadingImage = true;
|
||||
_lastUrl = url;
|
||||
});
|
||||
final image = NetworkImage(url);
|
||||
image.resolve(const ImageConfiguration()).addListener(
|
||||
ImageStreamListener(
|
||||
(info, _) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_profileImage = image;
|
||||
_isLoadingImage = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
onError: (error, stack) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_profileImage = null;
|
||||
_isLoadingImage = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
setState(() {
|
||||
_profileImage = null;
|
||||
_isLoadingImage = false;
|
||||
_lastUrl = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
@ -27,7 +87,7 @@ class UserCard extends StatelessWidget {
|
||||
elevation: 3,
|
||||
child: Container(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: isMobile ? double.infinity : _desktopMaxWidth,
|
||||
maxWidth: isMobile ? double.infinity : UserCard._desktopMaxWidth,
|
||||
),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child:
|
||||
@ -47,13 +107,13 @@ class UserCard extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"${user.firstName} ${user.lastName}",
|
||||
"${widget.user.firstName} ${widget.user.lastName}",
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
user.email,
|
||||
widget.user.email,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@ -65,7 +125,7 @@ class UserCard extends StatelessWidget {
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit, size: 20),
|
||||
onPressed: onEdit,
|
||||
onPressed: widget.onEdit,
|
||||
color: AppColors.rouge,
|
||||
padding: const EdgeInsets.all(8),
|
||||
constraints: const BoxConstraints(
|
||||
@ -75,7 +135,7 @@ class UserCard extends StatelessWidget {
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete, size: 20),
|
||||
onPressed: onDelete,
|
||||
onPressed: widget.onDelete,
|
||||
color: AppColors.gris,
|
||||
padding: const EdgeInsets.all(8),
|
||||
constraints: const BoxConstraints(
|
||||
@ -106,22 +166,22 @@ class UserCard extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"${user.firstName} ${user.lastName}",
|
||||
"${widget.user.firstName} ${widget.user.lastName}",
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
user.email,
|
||||
widget.user.email,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (user.role.isNotEmpty) ...[
|
||||
if (widget.user.role.isNotEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
user.role,
|
||||
widget.user.role,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: AppColors.gris,
|
||||
fontSize: 11,
|
||||
@ -143,7 +203,7 @@ class UserCard extends StatelessWidget {
|
||||
_buildButton(
|
||||
icon: Icons.edit,
|
||||
label: "Modifier",
|
||||
onPressed: onEdit,
|
||||
onPressed: widget.onEdit,
|
||||
color: AppColors.rouge,
|
||||
isNarrow: true,
|
||||
),
|
||||
@ -151,7 +211,7 @@ class UserCard extends StatelessWidget {
|
||||
_buildButton(
|
||||
icon: Icons.delete,
|
||||
label: "Supprimer",
|
||||
onPressed: onDelete,
|
||||
onPressed: widget.onDelete,
|
||||
color: AppColors.gris,
|
||||
isNarrow: true,
|
||||
),
|
||||
@ -163,7 +223,7 @@ class UserCard extends StatelessWidget {
|
||||
_buildButton(
|
||||
icon: Icons.edit,
|
||||
label: "Modifier",
|
||||
onPressed: onEdit,
|
||||
onPressed: widget.onEdit,
|
||||
color: AppColors.rouge,
|
||||
isNarrow: false,
|
||||
),
|
||||
@ -171,7 +231,7 @@ class UserCard extends StatelessWidget {
|
||||
_buildButton(
|
||||
icon: Icons.delete,
|
||||
label: "Supprimer",
|
||||
onPressed: onDelete,
|
||||
onPressed: widget.onDelete,
|
||||
color: AppColors.gris,
|
||||
isNarrow: false,
|
||||
),
|
||||
@ -218,13 +278,22 @@ class UserCard extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _profileAvatar(double size) {
|
||||
if (_isLoadingImage && widget.user.profilePhotoUrl.isNotEmpty) {
|
||||
return CircleAvatar(
|
||||
radius: size / 2,
|
||||
backgroundColor: Colors.grey[300],
|
||||
child: SizedBox(
|
||||
width: size * 0.5,
|
||||
height: size * 0.5,
|
||||
child: const CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
return CircleAvatar(
|
||||
radius: size / 2,
|
||||
backgroundImage: user.profilePhotoUrl.isNotEmpty
|
||||
? NetworkImage(user.profilePhotoUrl)
|
||||
: null,
|
||||
backgroundImage: _profileImage,
|
||||
backgroundColor: Colors.grey[200],
|
||||
child: user.profilePhotoUrl.isEmpty
|
||||
child: (widget.user.profilePhotoUrl.isEmpty || _profileImage == null)
|
||||
? Icon(Icons.person, size: size * 0.6, color: AppColors.noir)
|
||||
: null,
|
||||
);
|
||||
|
Reference in New Issue
Block a user