From 740733537172f51581abf5f360f8b9109223ba66 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Fri, 14 Aug 2026 15:35:13 +0200 Subject: [PATCH] =?UTF-8?q?Rapport=20PDF=20:=20emp=C3=AAcher=20les=20carte?= =?UTF-8?q?s=20de=20se=20couper=20entre=20deux=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pw.Container délègue canSpan à son enfant, si bien qu'une carte pouvait se scinder entre deux pages — titre seul en bas de l'une, contenu en haut de l'autre. Enveloppe le graphique et les groupes de barres dans un widget non sécable, que MultiPage reporte alors en entier. Les tableaux restent sécables : un tableau long doit pouvoir se répartir sur plusieurs pages. Co-Authored-By: Claude Opus 5 --- lib/Screens/Statistics/statistics_report.dart | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/Screens/Statistics/statistics_report.dart b/lib/Screens/Statistics/statistics_report.dart index df9c23a..585d933 100644 --- a/lib/Screens/Statistics/statistics_report.dart +++ b/lib/Screens/Statistics/statistics_report.dart @@ -303,7 +303,7 @@ pw.Widget _chart(StatisticsReportData data) { data.series.map((point) => point.visits).reduce((a, b) => a > b ? a : b); final axisMax = _roundedAxisMax(peak); - return _card( + return _Unbreakable(_card( data, title: data.chartTitle, subtitle: data.chartSubtitle, @@ -352,11 +352,11 @@ pw.Widget _chart(StatisticsReportData data) { ], ], ), - ); + )); } pw.Widget _barGroup(StatisticsReportData data, ReportBarGroup group) { - return _card( + return _Unbreakable(_card( data, title: group.title, subtitle: group.subtitle, @@ -388,7 +388,7 @@ pw.Widget _barGroup(StatisticsReportData data, ReportBarGroup group) { ), ], ), - ); + )); } pw.Widget _table(StatisticsReportData data, ReportTable table) { @@ -460,6 +460,22 @@ pw.Widget _barTrack(double fraction, PdfColor color) { ); } +/// `Container` délègue `canSpan` à son enfant : une carte se coupait donc entre +/// deux pages, titre seul en bas de l'une et contenu en haut de l'autre. +/// `MultiPage` reporte en entier tout enfant non sécable. +class _Unbreakable extends pw.SingleChildWidget { + _Unbreakable(pw.Widget child) : super(child: child); + + @override + bool get canSpan => false; + + @override + void paint(pw.Context context) { + super.paint(context); + paintChild(context); + } +} + double _roundedAxisMax(int peak) { if (peak <= 4) return 4; var magnitude = 1.0;