tablet-app-new/lib/Screens/Map/map_box_view.dart
Thomas Fransolet 9f582dd8a7 Lot K : tablet-app reconstruit et rebranché sur le contrat Postgres v3
Premier vrai build depuis avril. Le diagnostic des docs — « un seul défaut,
purement Gradle, peut-être réglé par 5a6701d » — tenait parce que personne
n'avait lancé la commande.

K1 — dix crans d'outillage, chacun dicté par l'erreur du précédent :
Gradle 7.5 → 8.11.1, AGP 7.2.0 → 8.9.1, Kotlin 1.9.0 → 2.3.10,
enableUncompressedNativeLibs retirée (supprimée en AGP 8.1), jcenter → mavenCentral,
heap 1536M → 4096M, Jetifier coupé, et retrait du resolutionStrategy qui forçait
androidx.lifecycle à 2.4.0 « to fix mapbox issue » : il réglait un problème d'il y
a trois ans et causait celui d'aujourd'hui, mapbox_maps_flutter 2.21.1 appelant
setViewTreeLifecycleOwner. Les trois derniers crans étaient de simples alignements
sur mymuseum-visitapp, qui utilise le même plugin sans ces problèmes.

Le bloc buildscript commenté de android/build.gradle est supprimé : il déclarait
une config qui n'était pas celle appliquée et a fait conclure deux fois à tort.

K2 — les 132 erreurs Dart que le Gradle masquait. Trois causes : roundedValue,
isDate, isHour, isSectionImageBackground et screenPercentageSectionsMainPage ont
migré vers AppConfigurationLink ; GeoPointDTO.latitude/longitude sont devenus
geometry ; le reste en découlait. Deux bugs latents trouvés au passage :

- applicationInstanceDTO n'était assigné que si l'instance avait l'IA — il servait
  de drapeau d'assistant. Ce DTO portant désormais les AppConfigurationLink, les
  cinq réglages seraient retombés sur leurs défauts sur MDLF et le Fort, sans
  erreur ni log. Drapeau rendu explicite, en préservant le ET instance × canal.
- ConfigurationDTO.isTablet ayant disparu, le filtre des configurations tablette
  n'avait plus de source : il porte sur les liens du canal AppType.Tablet.

La formule de clé par coordonnées de geo_point_filter, dupliquée à quatre endroits
alors que les deux côtés de l'appariement doivent produire la même valeur, ne vit
plus qu'à un seul (Helpers/geo.dart). Ce fichier documente aussi les deux
conventions de coordonnées du projet : [lng, lat] pour les GeoPoint, [lat, lng]
pour les géométries de GuidedStep.

K4 — l'écran Game repris de mymuseum-visitapp, Screens/Puzzle supprimé. La tablette
gagne le puzzle glissant, le bouton d'indice et un dimensionnement au ratio de
l'image. Les couleurs, codées en dur par flavor client chez mymuseum, sont dérivées
de configuration.primaryColor : tablet-app n'a pas de flavor, un seul APK sert tous
les clients.

Reste à vérifier sur device : le rendu de l'écran Game, et l'écran de sélection de
configuration, qui sera vide si les configurations ne sont pas rattachées au canal
tablette.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 12:18:07 +02:00

237 lines
8.6 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:manager_api_new/api.dart';
import 'package:tablet_app/Helpers/geo.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart' as mapBox;
import 'package:provider/provider.dart';
import 'package:tablet_app/Models/tabletContext.dart';
import 'package:tablet_app/Screens/Map/map_context.dart';
import 'package:html/parser.dart' show parse;
import 'package:tablet_app/Screens/Map/map_view.dart';
import 'package:tablet_app/app_context.dart';
class MapBoxView extends StatefulWidget {
final MapDTO? mapDTO;
final List<GeoPointDTO> geoPoints;
final List<Map<String, dynamic>> icons;
final String? language;
const MapBoxView({
Key? key,
this.mapDTO,
required this.geoPoints,
required this.icons,
this.language,
}) : super(key: key);
@override
_MapBoxViewState createState() => _MapBoxViewState();
}
class AnnotationClickListener extends mapBox.OnPointAnnotationClickListener {
late List<GeoPointDTO> markersList;
late MapContext mapContext;
AnnotationClickListener({
required this.markersList,
required this.mapContext,
});
@override
void onPointAnnotationClick(mapBox.PointAnnotation annotation) {
try{
var markerToShow = markersList.firstWhere((ml) => "${parse(ml.title!.first.value).documentElement!.text}${ml.lat}${ml.lng}" == annotation.textField);
mapContext.setSelectedPoint(markerToShow);
//mapContext.setSelectedPointForNavigate(markerToShow);
} catch(e) {
print("ISSSUE setSelectedMarker");
print(e);
}
}
}
class _MapBoxViewState extends State<MapBoxView> {
late mapBox.MapboxMap? mapboxMap;
mapBox.PointAnnotationManager? pointAnnotationManager;
bool filterZoneSelected = false;
createPoints() {
var options = <mapBox.PointAnnotationOptions>[];
int i = 0;
markersList = [];
pointsToShow!.forEach((point) {
if(point.title!.where((translation) => translation.language == widget.language).firstOrNull != null) {
var textSansHTML = parse(point.title!.firstWhere((translation) => translation.language == widget.language).value);
point.id = i;
point.title = point.title!.where((t) => t.language == widget.language).toList();
/*var mapMarker = new MapMarker(
id: i,
title: parse(textSansHTML.body!.text).documentElement!.text,
description: point.description!.firstWhere((translation) => translation.language == widget.language).value,
longitude: point.longitude,
latitude: point.latitude,
contents: point.contents
);*/
markersList.add(point);
options.add(mapBox.PointAnnotationOptions(
geometry: mapBox.Point(
coordinates: mapBox.Position(
point.lng!,
point.lat!,
)), // .toJson()
iconSize: 1.3,
textField: "${parse(textSansHTML.body!.text).documentElement!.text}${point.lat}${point.lng}",
textOpacity: 0.0,
iconOffset: [0.0, 0.0],
symbolSortKey: 10,
iconColor: 0,
iconImage: null,
image: point.categorieId == null ? widget.icons.where((i) => i['id'] == null).first['icon'] : widget.icons.any((i) => i['id'] == point.categorieId) ? widget.icons.where((i) => i['id'] == point.categorieId).first['icon'] : widget.icons.where((i) => i['id'] == null).first['icon'], //widget.selectedMarkerIcon,
)); // ,
i++;
}
});
print(options.length);
return options;
}
_onMapCreated(mapBox.MapboxMap mapboxMap, MapContext mapContext) {
this.mapboxMap = mapboxMap;
mapboxMap.annotations.createPointAnnotationManager().then((pointAnnotationManager) async {
this.pointAnnotationManager = pointAnnotationManager;
pointAnnotationManager.createMulti(createPoints());
pointAnnotationManager.addOnPointAnnotationClickListener(AnnotationClickListener(mapContext: mapContext, markersList: markersList));
init = true;
});
}
ConfigurationDTO? configurationDTO;
//Completer<GoogleMapController> _controller = Completer();
//Set<Marker> markers = {};
List<GeoPointDTO>? pointsToShow = [];
List<String>? selectedCategories = [];
bool init = false;
@override
void initState() {
pointsToShow = widget.geoPoints;//widget.mapDTO!.points;
var nonNullCat = widget.mapDTO!.categories!.where((c) => c.label!.where((element) => element.language == widget.language).firstOrNull != null);
selectedCategories = nonNullCat.map((categorie) => categorie.label!.firstWhere((element) => element.language == widget.language).value!).toList();
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
final mapContext = Provider.of<MapContext>(context);
pointsToShow = widget.geoPoints;//widget.mapDTO!.points;
if(pointAnnotationManager != null) {
pointAnnotationManager!.deleteAll();
pointAnnotationManager!.createMulti(createPoints());
//mapContext.notifyListeners();
}
final appContext = Provider.of<AppContext>(context);
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
Size size = MediaQuery.of(context).size;
var type = mapBox.MapboxStyles.STANDARD;
if(widget.mapDTO!.mapTypeMapbox != null) {
switch(widget.mapDTO!.mapTypeMapbox!) {
case MapTypeMapBox.standard:
type = mapBox.MapboxStyles.STANDARD;
break;
case MapTypeMapBox.streets:
type = mapBox.MapboxStyles.MAPBOX_STREETS;
break;
case MapTypeMapBox.outdoors:
type = mapBox.MapboxStyles.OUTDOORS;
break;
case MapTypeMapBox.light:
type = mapBox.MapboxStyles.LIGHT;
break;
case MapTypeMapBox.dark:
type = mapBox.MapboxStyles.DARK;
break;
case MapTypeMapBox.satellite:
type = mapBox.MapboxStyles.SATELLITE;
break;
case MapTypeMapBox.satellite_streets:
type = mapBox.MapboxStyles.SATELLITE_STREETS;
break;
}
}
return Stack(
children: [
Center(
child: mapBox.MapWidget(
key: ValueKey("mapBoxWidget"),
styleUri: type,
onMapCreated: (maBoxMap) {
_onMapCreated(maBoxMap, mapContext);
},
onTapListener: (listener) {
// close on tap
mapContext.setSelectedPoint(null);
mapContext.setSelectedPointForNavigate(null);
},
cameraOptions: mapBox.CameraOptions(
center: mapBox.Point(coordinates: widget.mapDTO!.longitude != null && widget.mapDTO!.latitude != null ? mapBox.Position(double.tryParse(widget.mapDTO!.longitude!)!, double.tryParse(widget.mapDTO!.latitude!)!) : mapBox.Position(4.865105, 50.465503)), //.toJson()
zoom: widget.mapDTO!.zoom != null ? widget.mapDTO!.zoom!.toDouble() : 12),
)
),
Container(
child: Builder(
builder: (context) {
return Consumer<MapContext>(
builder: (context, mapContext, _) {
var geoPoint = mapContext.getSelectedPointForNavigate() as GeoPointDTO?;
if (geoPoint != null && mapboxMap != null) {
print("COUCOU IL FAUT NAVUGATE MAPBOX");
// TODO Handle zoomDetail
mapboxMap?.easeTo(
mapBox.CameraOptions(
center: mapBox.Point(coordinates: mapBox.Position(geoPoint.lng!, geoPoint.lat!)), //.toJson()
zoom: 16,
bearing: 0,
pitch: 3),
mapBox.MapAnimationOptions(duration: 2000, startDelay: 0));
}
return SizedBox();
},
);
}
),
)
/*Positioned(
left: 5,
top: 35,
child: SizedBox(
width: size.width * 0.3,
height: size.height * 0.76,
child: GeoPointFilter(
language: tabletAppContext.language!,
geoPoints: widget.mapDTO!.points!,
categories: widget.mapDTO!.categories!,
filteredPoints: (filteredPoints) {
print("COUCOU FILTERED POINTS");
print(filteredPoints);
}),
),
),*/
],
);
}
}