1d3ee69c6d
App Flutter de programme de fidélité : login staff, clients (nom/prénom), scan QR, factures (€→points), récompenses, réglages. Backend Supabase (schéma SQL + RLS anti-triche dans supabase/). Icône incluse. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
101 lines
2.8 KiB
Dart
101 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
|
|
import '../services/client_repository.dart';
|
|
import '../services/recompense_repository.dart';
|
|
import '../services/reglages.dart';
|
|
import '../supabase_config.dart';
|
|
import 'home_shell.dart';
|
|
import 'staff_login_screen.dart';
|
|
|
|
/// Aiguille entre l'écran de connexion (staff non connecté) et l'app.
|
|
/// Écoute l'état d'authentification Supabase en continu.
|
|
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 StaffLoginScreen();
|
|
return const _AppChargee();
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Charge les données (réglages, clients, récompenses) après connexion, puis
|
|
/// affiche l'app. Recharge si le compte connecté change.
|
|
class _AppChargee extends StatefulWidget {
|
|
const _AppChargee();
|
|
|
|
@override
|
|
State<_AppChargee> createState() => _AppChargeeState();
|
|
}
|
|
|
|
class _AppChargeeState extends State<_AppChargee> {
|
|
late Future<void> _chargement;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_chargement = _charger();
|
|
}
|
|
|
|
Future<void> _charger() async {
|
|
await Reglages.instance.charger();
|
|
await ClientRepository.instance.charger();
|
|
await RecompenseRepository.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 const HomeShell();
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _EcranNonConfigure extends StatelessWidget {
|
|
const _EcranNonConfigure();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: const [
|
|
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.\n'
|
|
'Voir supabase/SETUP.md',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(color: Color(0xFF6B6B72)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|