(Feat) Migration PocketBase

This commit is contained in:
2026-07-18 11:51:32 +02:00
parent 1d3ee69c6d
commit e483fd9070
15 changed files with 522 additions and 453 deletions
+106 -4
View File
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../pocketbase_config.dart';
import '../services/client_repository.dart';
import '../services/reglages.dart';
import '../supabase_config.dart';
import '../theme.dart';
import '../utils/format.dart';
@@ -19,6 +20,8 @@ class _ReglagesScreenState extends State<ReglagesScreen> {
final _reglages = Reglages.instance;
late final TextEditingController _ratioCtrl;
late final TextEditingController _nomCtrl;
bool? _serveurOk; // null = en cours de vérification
bool _verifEnCours = false;
@override
void initState() {
@@ -27,6 +30,24 @@ class _ReglagesScreenState extends State<ReglagesScreen> {
text: _formaterRatio(_reglages.eurosParPoint),
);
_nomCtrl = TextEditingController(text: _reglages.nomMagasin);
_verifierServeur();
}
Future<void> _verifierServeur() async {
setState(() => _verifEnCours = true);
bool ok;
try {
await pb.health.check();
ok = true;
} catch (_) {
ok = false;
}
if (mounted) {
setState(() {
_serveurOk = ok;
_verifEnCours = false;
});
}
}
@override
@@ -155,12 +176,15 @@ class _ReglagesScreenState extends State<ReglagesScreen> {
),
),
const SizedBox(height: 24),
_titre('Serveur'),
_carteServeur(),
const SizedBox(height: 24),
_titre('À propos'),
const Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Text(
'Données partagées via Supabase avec l\'app client. '
'Données hébergées sur le serveur PocketBase du magasin. '
'Le scan se fait avec la caméra ; la scanette externe sera '
'branchée dans une prochaine version.',
style: TextStyle(color: AppTheme.grisTexte, height: 1.4),
@@ -197,7 +221,10 @@ class _ReglagesScreenState extends State<ReglagesScreen> {
);
}
String? _emailConnecte() => supabase.auth.currentUser?.email;
String? _emailConnecte() {
final email = pb.authStore.record?.getStringValue('email');
return (email == null || email.isEmpty) ? null : email;
}
Future<void> _deconnexion() async {
final ok = await showDialog<bool>(
@@ -217,7 +244,7 @@ class _ReglagesScreenState extends State<ReglagesScreen> {
],
),
);
if (ok == true) await supabase.auth.signOut();
if (ok == true) pb.authStore.clear();
}
Widget _apercus() {
@@ -255,6 +282,81 @@ class _ReglagesScreenState extends State<ReglagesScreen> {
);
}
Widget _carteServeur() {
final syncOk = ClientRepository.instance.tempsReelActif;
return Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.dns_outlined,
size: 18, color: AppTheme.grisTexte),
const SizedBox(width: 8),
Expanded(
child: Text(
PocketBaseConfig.url,
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
],
),
const Divider(height: 22),
Row(
children: [
Expanded(
child: _verifEnCours
? _ligneStatut(null, 'Vérification…')
: _ligneStatut(_serveurOk, 'Connecté au serveur',
koTexte: 'Serveur injoignable'),
),
if (_verifEnCours)
const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
else
IconButton(
tooltip: 'Revérifier',
icon: const Icon(Icons.refresh),
onPressed: _verifierServeur,
),
],
),
const SizedBox(height: 8),
_ligneStatut(syncOk, 'Synchronisation temps réel active',
koTexte: 'Temps réel inactif'),
],
),
),
);
}
Widget _ligneStatut(bool? ok, String texte, {String? koTexte}) {
final couleur = ok == null
? AppTheme.grisTexte
: (ok ? Colors.green.shade600 : Colors.red.shade600);
return Row(
children: [
Container(
width: 10,
height: 10,
decoration: BoxDecoration(color: couleur, shape: BoxShape.circle),
),
const SizedBox(width: 8),
Expanded(
child: Text(
(ok == false && koTexte != null) ? koTexte : texte,
style: TextStyle(color: couleur, fontWeight: FontWeight.w600),
),
),
],
);
}
Widget _titre(String texte) {
return Padding(
padding: const EdgeInsets.fromLTRB(4, 0, 4, 10),