petitspas/frontend/lib/widgets/hover_relief_widget.dart
Julien Martin 110240b682 feat(frontend): inscription — UI cartes enfant, formatage noms, focus Tab
- Formulaire infos perso : ordre de tabulation explicite, Checkbox Material
  pour le consentement photo, formatage nom/prénom/ville à la perte de focus
  et à la soumission (name_format_utils).
- Carte enfant : cadre photo, croix, ombres, consentement ; formatage
  prénom/nom enfant ; normalisation avant passage étape 4.
- Asset photo_frame.png ; HoverReliefWidget clipBehavior.
- Ajustements payload / modèle / étapes inscription liés au parcours.

Made-with: Cursor
2026-03-28 20:40:27 +01:00

91 lines
3.4 KiB
Dart

import 'package:flutter/material.dart';
class HoverReliefWidget extends StatefulWidget {
final Widget child;
final VoidCallback? onPressed;
final BorderRadius borderRadius;
final double initialElevation;
final double hoverElevation;
final double scaleFactor;
final bool enableHoverEffect; // Pour activer/désactiver l'effet de survol
final Color initialShadowColor; // Nouveau paramètre
final Color hoverShadowColor; // Nouveau paramètre
/// `Clip.none` : ne pas découper le child (ex. trou du cadre PNG par-dessus la photo).
final Clip clipBehavior;
const HoverReliefWidget({
required this.child,
this.onPressed,
this.borderRadius = const BorderRadius.all(Radius.circular(15.0)),
this.initialElevation = 4.0,
this.hoverElevation = 8.0,
this.scaleFactor = 1.03, // Légèrement réduit par rapport à l'exemple précédent
this.enableHoverEffect = true, // Par défaut, l'effet est activé
this.initialShadowColor = const Color(0x26000000), // Default: Colors.black.withOpacity(0.15)
this.hoverShadowColor = const Color(0x4D000000), // Default: Colors.black.withOpacity(0.3)
this.clipBehavior = Clip.antiAlias,
super.key,
});
@override
State<HoverReliefWidget> createState() => _HoverReliefWidgetState();
}
class _HoverReliefWidgetState extends State<HoverReliefWidget> {
bool _isHovering = false;
@override
Widget build(BuildContext context) {
final bool canHover = widget.enableHoverEffect && widget.onPressed != null;
final hoverTransform = Matrix4.identity()..scale(widget.scaleFactor);
final transform = _isHovering && canHover ? hoverTransform : Matrix4.identity();
final shadowColor = _isHovering && canHover ? widget.hoverShadowColor : widget.initialShadowColor;
final elevation = _isHovering && canHover ? widget.hoverElevation : widget.initialElevation;
Widget content = AnimatedContainer(
duration: const Duration(milliseconds: 200),
transform: transform,
transformAlignment: Alignment.center,
child: Material(
color: Colors.transparent,
elevation: elevation,
shadowColor: shadowColor,
borderRadius: widget.borderRadius,
clipBehavior: widget.clipBehavior,
child: widget.child,
),
);
if (widget.onPressed == null) {
// Si non cliquable, on retourne juste le contenu avec l'élévation initiale (pas de survol)
// Ajustement: pour toujours avoir un Material de base même si non cliquable et sans hover.
return Material(
color: Colors.transparent,
elevation: widget.initialElevation, // Utilise l'élévation initiale
shadowColor: widget.initialShadowColor, // Appliqué ici pour l'état non cliquable
borderRadius: widget.borderRadius,
clipBehavior: widget.clipBehavior,
child: widget.child,
);
}
return MouseRegion(
onEnter: (_) {
if (widget.enableHoverEffect) setState(() => _isHovering = true);
},
onExit: (_) {
if (widget.enableHoverEffect) setState(() => _isHovering = false);
},
cursor: SystemMouseCursors.click,
child: InkWell(
onTap: widget.onPressed,
borderRadius: widget.borderRadius,
hoverColor: Colors.transparent,
splashColor: Colors.grey.withOpacity(0.2),
highlightColor: Colors.grey.withOpacity(0.1),
child: content,
),
);
}
}