import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../services/session_client.dart';
import '../theme.dart';
/// Logo « G » officiel de Google (SVG des guidelines de marque). Ne pas altérer
/// (couleurs / proportions) sous peine de non-conformité (validation Play Store).
const String _googleGSvg = '''
''';
/// Bouton officiel « Se connecter avec Google » (connexion native, sélecteur de
/// compte in-app), conforme aux guidelines de marque Google. Un compte inconnu
/// est créé côté serveur puis dirigé vers l'écran « Finaliser mon profil ».
class OAuthBoutons extends StatefulWidget {
const OAuthBoutons({super.key});
@override
State createState() => _OAuthBoutonsState();
}
class _OAuthBoutonsState extends State {
bool _enCours = false;
Future _google() async {
setState(() => _enCours = true);
try {
await SessionClient.instance.connexionGoogleNative();
// Succès : l'AuthGate bascule automatiquement (ce widget est démonté).
} catch (e) {
if (mounted) {
setState(() => _enCours = false);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Connexion Google annulée ou échouée.')),
);
}
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text('ou',
style: TextStyle(color: AppTheme.grisTexte, fontSize: 13)),
),
const Expanded(child: Divider()),
],
),
const SizedBox(height: 12),
_BoutonGoogle(enCours: _enCours, onPressed: _enCours ? null : _google),
],
);
}
}
/// Rendu conforme charte Google : fond blanc, bordure #747775, logo G 18dp,
/// libellé Roboto Medium #1F1F1F.
class _BoutonGoogle extends StatelessWidget {
const _BoutonGoogle({required this.enCours, required this.onPressed});
final bool enCours;
final VoidCallback? onPressed;
static const Color _texte = Color(0xFF1F1F1F);
static const Color _bordure = Color(0xFF747775);
@override
Widget build(BuildContext context) {
return Material(
color: Colors.white,
borderRadius: BorderRadius.circular(14),
child: InkWell(
borderRadius: BorderRadius.circular(14),
onTap: onPressed,
child: Ink(
height: 52,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: _bordure),
),
child: Center(
child: enCours
? const SizedBox(
height: 22,
width: 22,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
SvgPicture.string(_googleGSvg, width: 18, height: 18),
const SizedBox(width: 12),
const Text(
'Se connecter avec Google',
style: TextStyle(
color: _texte,
fontSize: 15,
fontWeight: FontWeight.w500,
fontFamily: 'Roboto',
),
),
],
),
),
),
),
);
}
}