100 lines
2.9 KiB
Dart
100 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:pocketbase/pocketbase.dart';
|
|
|
|
import '../pocketbase_config.dart';
|
|
import '../services/session_client.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 (!PbConfig.estConfigure) return const _EcranNonConfigure();
|
|
|
|
return StreamBuilder<AuthStoreEvent>(
|
|
stream: pb.authStore.onChange,
|
|
builder: (context, snapshot) {
|
|
if (!pb.authStore.isValid) return const WelcomeScreen();
|
|
final uid = pb.authStore.record?.id ?? '';
|
|
return _SessionChargee(key: ValueKey(uid));
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 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('Backend non configuré',
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700)),
|
|
SizedBox(height: 8),
|
|
Text(
|
|
'Renseignez l\'URL PocketBase dans lib/pocketbase_config.dart.',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(color: Color(0xFF6B6B72)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|