import 'package:flutter/material.dart'; class PasswordStrengthIndicator extends StatelessWidget { final String password; const PasswordStrengthIndicator({Key? key, required this.password}) : super(key: key); static int _score(String p) { int s = 0; if (p.length >= 8) s++; if (p.contains(RegExp(r'[A-Z]'))) s++; if (p.contains(RegExp(r'[0-9]'))) s++; if (p.contains(RegExp(r'[!@#\$%^&*(),.?":{}|<>_\-]'))) s++; return s; } static const _labels = ['Muy débil', 'Débil', 'Regular', 'Buena', 'Fuerte']; static const _colors = [ Color(0xFF7B0000), Color(0xFFB71C1C), Color(0xFFE65100), Color(0xFFF9A825), Color(0xFF2E7D32), ]; @override Widget build(BuildContext context) { if (password.isEmpty) return const SizedBox.shrink(); final score = _score(password); final fraction = (score + 1) / 5; final color = _colors[score]; final label = _labels[score]; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 6), ClipRRect( borderRadius: BorderRadius.circular(4), child: LinearProgressIndicator( value: fraction, backgroundColor: const Color(0xFF1E4070), valueColor: AlwaysStoppedAnimation(color), minHeight: 5, ), ), const SizedBox(height: 4), Text( label, style: TextStyle(color: color, fontSize: 11), ), ], ); } }