Le fil rouge de ces corrections : des replis silencieux. Une exception rattrapee, une image absente, un fichier local jamais rattache — rien ne plantait, mais rien ne marchait non plus, et aucun message ne le disait. Splash et loader - assets/splash et assets/loader ne contenaient que des PNG 1x1 transparents. errorBuilder ne se declenche pas : le fichier est valide, juste vide. Logo et loader etaient donc invisibles PARTOUT, splash comme ecrans de chargement. assets/loader est supprime, kLoaderAsset avec. - Le splash natif etait blanc (launch_background en @android:color/white, theme Light) puis l'app basculait en sombre. Fond unifie sur #111111, cote natif comme Dart, avec values-v31 : Android 12+ ignore windowBackground et repart sur le theme sans ces attributs. - Le loader et l'image principale viennent maintenant du manager (Applications -> Mobile). InstanceImages les garde sur le device : le splash s'affiche avant tout appel API, il ne peut lire qu'un cache. Alimente au boot depuis instanceGetDetail, qui porte deja les ApplicationInstances — aucun appel supplementaire. - Ouvrir une section montrait une page blanche avec un loader au milieu. SlideFromRightRoute devient non opaque et SectionPage garde un fond transparent tant que la section n'est pas prete : le visiteur garde sous les yeux l'ecran d'ou il vient. Hors ligne - L'audio d'un article ne repartait jamais du MP3 local : audioFile n'etait jamais renseigne, le lecteur retombait toujours sur l'URL. - L'image de titre d'un article passait par NetworkImage, donc une croix rouge des que le reseau manque, alors que le fichier est sur le device. - L'accueil ne gardait en base que order/gridSpan : une visite jamais telechargee disparaissait de la grille hors ligne. La visite entiere est desormais mise en cache, et une visite injoignable reste affichee, ternie et non ouvrable, plutot qu'absente. - L'etat reseau datait du premier chargement et n'etait jamais remesure. WidgetsBindingObserver etait declare mais jamais enregistre : aucun rappel n'arrivait. L'accueil se recharge au retour dans l'app et remesure avant de refuser l'ouverture d'une visite. Divers - Le futur de getSectionDetail etait construit dans future:, donc relance a chaque rebuild — chaque rotation d'ecran refaisait l'appel reseau. - ImageCustomProvider listait le repertoire d'une visite non telechargee : exception a chaque construction de chaque image, pour finir de toute facon sur le reseau. - Scanner un QR d'une autre visite empilait les ConfigurationPage. pushAndRemoveUntil : une visite est une destination de premier niveau. - Le scanner arrive sur l'accueil, en pastille de verre comme les autres actions de cet ecran. ScannerBouton prend size et transparent, et garde son apparence d'origine ailleurs. - Le titre d'un article n'etait pas centre : customStylesBuilder ne s'applique qu'aux elements, et un titre sans balise n'en a aucun. - Le lecteur audio replie ne lancait pas la lecture au premier appui, il ouvrait le panneau. Il lit, puis ouvre. En lecture auto il reste replie. - Le dialogue de telechargement faisait la hauteur de l'ecran : un Center prend toute la hauteur maximale que lui donne un AlertDialog. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
282 lines
10 KiB
Dart
282 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'dart:io';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:mymuseum_visitapp/Components/SlideFromRouteRight.dart';
|
|
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
|
import 'package:mymuseum_visitapp/Screens/ConfigurationPage/configuration_page.dart';
|
|
import 'package:mymuseum_visitapp/Screens/section_page.dart';
|
|
import 'package:mymuseum_visitapp/app_context.dart';
|
|
import 'package:mymuseum_visitapp/constants.dart';
|
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
|
|
|
class ScannerDialog extends StatefulWidget {
|
|
const ScannerDialog({Key? key, required this.appContext}) : super(key: key);
|
|
|
|
final AppContext? appContext;
|
|
|
|
@override
|
|
State<ScannerDialog> createState() => _ScannerDialogState();
|
|
}
|
|
|
|
class _ScannerDialogState extends State<ScannerDialog> {
|
|
final MobileScannerController controller = MobileScannerController();
|
|
bool isProcessing = false;
|
|
|
|
@override
|
|
void reassemble() {
|
|
super.reassemble();
|
|
if (Platform.isAndroid) {
|
|
controller.stop();
|
|
}
|
|
controller.start();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
return Container(
|
|
height: size.height * 0.5,
|
|
width: size.width * 0.9,
|
|
child: Stack(
|
|
children: [
|
|
Center(
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
child: MobileScanner(
|
|
controller: controller,
|
|
//allowDuplicates: false,
|
|
onDetect: (barcodes) => _onDetect(barcodes),
|
|
),
|
|
),
|
|
),
|
|
_buildControlButton(
|
|
icon: Icons.flash_on,
|
|
onTap: () => controller.toggleTorch(),
|
|
alignment: Alignment.topRight,
|
|
),
|
|
_buildControlButton(
|
|
icon: Icons.flip_camera_android,
|
|
onTap: () => controller.switchCamera(),
|
|
alignment: Alignment.bottomRight,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildControlButton({
|
|
required IconData icon,
|
|
required VoidCallback onTap,
|
|
required Alignment alignment,
|
|
}) {
|
|
return Align(
|
|
alignment: alignment,
|
|
child: Container(
|
|
width: 45,
|
|
height: 45,
|
|
margin: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.rectangle,
|
|
color: kMainColor1,
|
|
borderRadius: BorderRadius.circular(20.0),
|
|
),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Icon(icon, color: Colors.white),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _onDetect(BarcodeCapture capture) async {
|
|
if (isProcessing) return;
|
|
|
|
final barcode = capture.barcodes.first;
|
|
final code = barcode.rawValue ?? "";
|
|
|
|
if (barcode.format == BarcodeFormat.qrCode && code.isNotEmpty) {
|
|
isProcessing = true;
|
|
|
|
RegExp regExp = RegExp(r'^(?:https:\/\/web\.myinfomate\.be\/([^\/]+)\/([^\/]+)\/([^\/]+)|([^\/]+))$');
|
|
RegExp regExp2 = RegExp(r'^(?:https:\/\/web\.mymuseum\.be\/([^\/]+)\/([^\/]+)\/([^\/]+)|([^\/]+))$');
|
|
var match = regExp.firstMatch(code);
|
|
var match2 = regExp2.firstMatch(code);
|
|
String? instanceId;
|
|
String? configurationId;
|
|
String? sectionId;
|
|
|
|
if(match == null) {
|
|
instanceId = match2?.group(1);
|
|
configurationId = match2?.group(2);
|
|
sectionId = match2?.group(3) ?? match2?.group(4);
|
|
} else {
|
|
instanceId = match.group(1);
|
|
configurationId = match.group(2);
|
|
sectionId = match.group(3) ?? match.group(4);
|
|
}
|
|
|
|
if ((match == null && match2 == null) || sectionId == null) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text("L'URL ne correspond pas au format attendu."), backgroundColor: kMainColor2),
|
|
);
|
|
Navigator.of(context).pop();
|
|
return;
|
|
}
|
|
|
|
VisitAppContext visitAppContext = widget.appContext!.getContext();
|
|
|
|
if (visitAppContext.sectionIds == null || !visitAppContext.sectionIds!.contains(sectionId)) {
|
|
visitAppContext.statisticsService?.track(VisitEventType.qrScan, metadata: {'valid': false, 'sectionId': sectionId});
|
|
|
|
// Le QR porte l'id de sa configuration, jusqu'ici parsé puis jeté. Un code
|
|
// d'une autre visite du site tombait donc dans « QR code invalide », qui
|
|
// laisse croire à un code abîmé alors qu'il est parfaitement lisible.
|
|
final other = await _findOtherConfiguration(visitAppContext, configurationId);
|
|
if (!mounted) return;
|
|
|
|
// Capturés AVANT le pop : fermer la boîte du scanner démonte ce State, et
|
|
// tout ce qui repasse ensuite par son `context` — la navigation depuis le
|
|
// bouton « Ouvrir », touché quelques secondes plus tard — ne fait rien.
|
|
final navigator = Navigator.of(context);
|
|
final messenger = ScaffoldMessenger.of(context);
|
|
navigator.pop();
|
|
|
|
if (other != null) {
|
|
_proposeOtherVisit(navigator, visitAppContext, other, sectionId);
|
|
} else {
|
|
messenger.showSnackBar(
|
|
SnackBar(content: Text(TranslationHelper.getFromLocale('invalidQRCode', visitAppContext)), backgroundColor: kMainColor2),
|
|
);
|
|
}
|
|
} else {
|
|
visitAppContext.statisticsService?.track(VisitEventType.qrScan, sectionId: sectionId, metadata: {'valid': true});
|
|
// `orElse` : sans lui, le moindre écart entre `sectionIds` et
|
|
// `currentSections` levait un StateError non rattrapé, en plein scan.
|
|
dynamic rawSection = visitAppContext.currentSections
|
|
?.firstWhere((cs) => cs?['id'] == sectionId, orElse: () => null);
|
|
Navigator.of(context).pop();
|
|
|
|
if (rawSection == null) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(TranslationHelper.getFromLocale('invalidQRCode', visitAppContext)), backgroundColor: kMainColor2),
|
|
);
|
|
return;
|
|
}
|
|
|
|
Navigator.push(
|
|
context,
|
|
SlideFromRightRoute(page: SectionPage(
|
|
configuration: visitAppContext.configuration!,
|
|
rawSection: rawSection,
|
|
visitAppContextIn: visitAppContext,
|
|
sectionId: rawSection['id'],
|
|
)),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// La configuration du QR, si elle existe et n'est pas celle qu'on lit déjà.
|
|
/// La base locale d'abord — c'est la seule source hors ligne — puis l'API.
|
|
Future<ConfigurationDTO?> _findOtherConfiguration(
|
|
VisitAppContext visitAppContext, String? configurationId) async {
|
|
if (configurationId == null || configurationId == visitAppContext.configuration?.id) {
|
|
return null;
|
|
}
|
|
|
|
final local = await DatabaseHelper.instance
|
|
.queryWithColumnId(DatabaseTableType.configurations, configurationId);
|
|
if (local.isNotEmpty) {
|
|
return DatabaseHelper.instance.getConfigurationFromDB(local.first);
|
|
}
|
|
|
|
try {
|
|
return await visitAppContext.clientAPI.configurationApi!
|
|
.configurationGetDetail(configurationId);
|
|
} catch (e) {
|
|
debugPrint("[scan] configuration $configurationId introuvable : $e");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
Future<void> _proposeOtherVisit(NavigatorState navigator,
|
|
VisitAppContext visitAppContext, ConfigurationDTO other, String sectionId) async {
|
|
final name = TranslationHelper.getPlain(other.title, visitAppContext);
|
|
|
|
// Une visite hors ligne non téléchargée n'a rien à afficher : on nomme la
|
|
// visite sans proposer de l'ouvrir sur du vide.
|
|
final sections = await DatabaseHelper.instance
|
|
.queryWithConfigurationId(DatabaseTableType.sections, other.id!);
|
|
final canOpen = other.isOffline != true || sections.isNotEmpty;
|
|
|
|
showDialog(
|
|
context: navigator.context,
|
|
builder: (dialogContext) => AlertDialog(
|
|
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))),
|
|
title: Text(name, textAlign: TextAlign.center),
|
|
content: Text(
|
|
TranslationHelper.getFromLocale('qrOtherVisit', visitAppContext),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
actionsAlignment: MainAxisAlignment.center,
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(dialogContext).pop(),
|
|
child: Text(TranslationHelper.getFromLocale('close', visitAppContext)),
|
|
),
|
|
if (canOpen)
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(dialogContext).pop();
|
|
visitAppContext.configuration = other;
|
|
visitAppContext.sectionIds = null;
|
|
widget.appContext!.setContext(visitAppContext);
|
|
// `pushAndRemoveUntil` jusqu'à l'accueil, et non `push` : une visite
|
|
// est une destination de premier niveau, pas quelque chose qui
|
|
// s'empile. En scannant des QR de trois visites différentes, le
|
|
// visiteur se retrouvait avec trois ConfigurationPage superposées et
|
|
// autant de retours à faire pour revenir à l'accueil — en gardant en
|
|
// mémoire des visites qu'il a quittées. Ici la pile reste
|
|
// « accueil → visite en cours ».
|
|
navigator.pushAndRemoveUntil(
|
|
SlideFromRightRoute(
|
|
page: ConfigurationPage(
|
|
configuration: other,
|
|
isAlreadyAllowed: visitAppContext.isScanBeaconAlreadyAllowed,
|
|
openSectionId: sectionId,
|
|
),
|
|
),
|
|
(route) => route.isFirst,
|
|
);
|
|
},
|
|
child: Text(TranslationHelper.getFromLocale('open', visitAppContext)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
showScannerDialog(BuildContext context, AppContext appContext) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) => AlertDialog(
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
|
),
|
|
content: ScannerDialog(appContext: appContext),
|
|
contentPadding: EdgeInsets.zero,
|
|
),
|
|
);
|
|
}
|