tablet-app-new/lib/Screens/Menu/menu_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

207 lines
9.4 KiB
Dart

import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:manager_api_new/api.dart';
import 'package:provider/provider.dart';
import 'package:tablet_app/Components/loading_common.dart';
import 'package:tablet_app/Helpers/ImageCustomProvider.dart';
import 'package:tablet_app/Models/tabletContext.dart';
import 'package:tablet_app/Screens/MainView/main_view.dart';
import 'package:tablet_app/Screens/MainView/section_page_detail.dart';
import 'package:tablet_app/app_context.dart';
import 'package:tablet_app/constants.dart';
class MenuView extends StatefulWidget {
final MenuDTO section;
final bool isImageBackground;
MenuView({required this.section, required this.isImageBackground});
@override
_MenuView createState() => _MenuView();
}
class _MenuView extends State<MenuView> {
//MenuDTO menuDTO = MenuDTO();
SectionDTO? selectedSection;
bool isImageBackground = false;
late List<dynamic> rawSubSectionsData;
late List<SectionDTO> subSections;
@override
void initState() {
/*print(widget.section.data);
menuDTO = MenuDTO.fromJson(jsonDecode(widget.section.data!))!;
print(menuDTO);*/
//menuDTO = widget.section;
rawSubSectionsData = jsonDecode(jsonEncode(widget.section.sections));
//menuDTO.sections!.sort((a, b) => a.order!.compareTo(b.order!)); // useless, we get these after that
subSections = jsonDecode(jsonEncode(rawSubSectionsData)).map((json) => SectionDTO.fromJson(json)).whereType<SectionDTO>().toList();
isImageBackground = widget.isImageBackground;
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
final appContext = Provider.of<AppContext>(context);
Size size = MediaQuery.of(context).size;
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
ConfigurationDTO configurationDTO = appContext.getContext().configuration;
Color backgroundColor = appContext.getContext().configuration != null ? new Color(int.parse(appContext.getContext().configuration.secondaryColor.split('(0x')[1].split(')')[0], radix: 16)) : Colors.white;
Color textColor = backgroundColor.computeLuminance() > 0.5 ? Colors.black : Colors.white;
return Center(
child: GridView.builder(
shrinkWrap: true,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: kIsWeb ? 1.7 : 1.3),
itemCount: subSections.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: () {
//SectionDTO? section = await (appContext.getContext() as TabletAppContext).clientAPI!.sectionApi!.sectionGetDetail(menuDTO.sections![index].id!);
SectionDTO section = subSections[index];
var rawSectionData = rawSubSectionsData[index];
tabletAppContext.statisticsService?.track(
VisitEventType.menuItemTap,
metadata: {'targetSectionId': section.id, 'menuItemTitle': section.title?.where((t) => t.language == tabletAppContext.language).firstOrNull?.value},
);
setState(() {
//selectedSection = section;
//selectedSection = menuDTO.sections![index];
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return SectionPageDetail(configurationDTO: configurationDTO, sectionDTO: section, textColor: textColor, isImageBackground: isImageBackground, elementToShow: getContent(tabletAppContext, section, isImageBackground, rawSectionData), isFromMenu: true);
},
),// For pushAndRemoveUntil
);
});
},
child: Container(
decoration: isImageBackground ? boxDecoration(appContext, subSections[index], false, rawSubSectionsData[index]) : null,
padding: const EdgeInsets.all(20),
margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
child: isImageBackground ? Align(
alignment: Alignment.bottomRight,
child: FractionallySizedBox(
heightFactor: 0.5,
child: Column(
children: [
Align(
alignment: Alignment.centerRight,
child: HtmlWidget(
subSections[index].title!.where((translation) => translation.language == appContext.getContext().language).firstOrNull?.value ?? "",
customStylesBuilder: (element) {
return {'text-align': 'right', 'font-family': "Roboto"};
},
textStyle: new TextStyle(fontSize: kMenuTitleDetailSize),
),
),
/*Align(
alignment: Alignment.centerRight,
child: HtmlWidget(
menuDTO.sections![index].description!.firstWhere((translation) => translation.language == appContext.getContext().language).value!,
customStylesBuilder: (element) {
return {'text-align': 'right'};
},
textStyle: new TextStyle(fontSize: kIsWeb? kWebSectionDescriptionDetailSize: kSectionDescriptionDetailSize, fontFamily: ""),
),
),*/
],
)
),
) : Column(
children: [
Expanded(
flex: 7,
child: Container(
decoration: BoxDecoration(
color: subSections[index].imageSource == null && subSections[index].type != SectionType.Video ? kBackgroundColor : null, // default color if no image
shape: BoxShape.rectangle,
image: subSections[index].imageSource != null || subSections[index].type == SectionType.Video ? new DecorationImage(
fit: BoxFit.contain, // contain or cover ?
image: ImageCustomProvider.getImageProvider(appContext, subSections[index].imageId, subSections[index].type == SectionType.Video ? getYoutubeThumbnailUrl(rawSubSectionsData[index]) : subSections[index].imageSource!),
): null,
),
)
),
Expanded(
flex: 3,
child: Container(
//color: Colors.yellow,
constraints: BoxConstraints(
maxWidth: size.width * 0.3,
),
child: Center(
child: HtmlWidget(
subSections[index].title!.where((translation) => translation.language == appContext.getContext().language).firstOrNull?.value ?? "",
customStylesBuilder: (element) {
return {'text-align': 'center', 'font-family': "Roboto"};
},
textStyle: TextStyle(fontSize: 20),//calculateFontSize(constraints.maxWidth, constraints.maxHeight, kIsWeb ? kWebMenuTitleDetailSize : kMenuTitleDetailSize)),
),
),
)
)
],
),
),
);
}
),
);
}
}
boxDecoration(AppContext appContext, SectionDTO section, bool isSelected, Object rawSubSectionData) {
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
return BoxDecoration(
color: kBackgroundLight,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(tabletAppContext.currentAppConfigurationLink?.roundedValue?.toDouble() ?? 20.0),
image: section.imageSource != null || section.type == SectionType.Video ? new DecorationImage(
fit: BoxFit.cover,
colorFilter: !isSelected? new ColorFilter.mode(kBackgroundLight.withValues(alpha: 0.35), BlendMode.dstATop) : null,
image: ImageCustomProvider.getImageProvider(appContext, section.imageId, section.type == SectionType.Video ? getYoutubeThumbnailUrl(rawSubSectionData) : section.imageSource!),
): null,
boxShadow: [
BoxShadow(
color: kBackgroundSecondGrey,
spreadRadius: 0.3,
blurRadius: 5,
offset: Offset(0, 1.5), // changes position of shadow
),
],
);
}
String getYoutubeThumbnailUrl(Object rawSectionData) {
try{
VideoDTO videoDTO = VideoDTO.fromJson(rawSectionData)!;
String thumbnailUrl = "";
if(videoDTO.source_ != null) {
//VideoDTO? videoDTO = VideoDTO.fromJson(jsonDecode(sectionDTO.data!));
Uri uri = Uri.parse(videoDTO.source_!);
String videoId = uri.queryParameters['v']!;
// Construire l'URL du thumbnail en utilisant l'identifiant de la vidéo YouTube
thumbnailUrl = 'https://img.youtube.com/vi/$videoId/0.jpg';
}
return thumbnailUrl;
} catch(e) {
return "";
}
}