Initial commit: app Fideliter client (Flutter)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import '../services/session_client.dart';
|
||||
import '../supabase_config.dart';
|
||||
import 'complete_profile_screen.dart';
|
||||
import 'home_client_screen.dart';
|
||||
import 'welcome_screen.dart';
|
||||
|
||||
/// Aiguille entre l'accueil non connecté, la finalisation de profil et l'app.
|
||||
class AuthGate extends StatelessWidget {
|
||||
const AuthGate({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!SupabaseConfig.estConfigure) return const _EcranNonConfigure();
|
||||
|
||||
return StreamBuilder<AuthState>(
|
||||
stream: supabase.auth.onAuthStateChange,
|
||||
builder: (context, snapshot) {
|
||||
final session = supabase.auth.currentSession;
|
||||
if (session == null) return const WelcomeScreen();
|
||||
return _SessionChargee(key: ValueKey(session.user.id));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge les données du client connecté, puis affiche l'app (ou la
|
||||
/// finalisation de profil si le compte n'a pas encore de fiche fidélité).
|
||||
class _SessionChargee extends StatefulWidget {
|
||||
const _SessionChargee({super.key});
|
||||
|
||||
@override
|
||||
State<_SessionChargee> createState() => _SessionChargeeState();
|
||||
}
|
||||
|
||||
class _SessionChargeeState extends State<_SessionChargee> {
|
||||
late Future<void> _chargement;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_chargement = SessionClient.instance.charger();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<void>(
|
||||
future: _chargement,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
return AnimatedBuilder(
|
||||
animation: SessionClient.instance,
|
||||
builder: (context, _) {
|
||||
final aProfil = SessionClient.instance.monClient != null;
|
||||
return aProfil
|
||||
? const HomeClientScreen()
|
||||
: const CompleteProfileScreen();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EcranNonConfigure extends StatelessWidget {
|
||||
const _EcranNonConfigure();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.cloud_off, size: 56, color: Colors.grey),
|
||||
SizedBox(height: 16),
|
||||
Text('Supabase non configuré',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700)),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Renseignez l\'URL et la clé anon dans lib/supabase_config.dart.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Color(0xFF6B6B72)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user