diff --git a/pdf/lib/src/widgets/chart/bar_chart.dart b/pdf/lib/src/widgets/chart/bar_chart.dart index a0c824ba..ff9f858c 100644 --- a/pdf/lib/src/widgets/chart/bar_chart.dart +++ b/pdf/lib/src/widgets/chart/bar_chart.dart @@ -17,7 +17,6 @@ import '../../../pdf.dart'; import '../flex.dart'; import '../geometry.dart'; -import '../page.dart'; import '../widget.dart'; import 'chart.dart'; import 'grid_cartesian.dart'; @@ -39,7 +38,7 @@ class BarDataSet extends PointDataSet { PdfColor? pointColor, double pointSize = 3, bool drawPoints = false, - BuildCallback? shape, + LegendBuildCallback? shape, Widget Function(Context context, T value)? buildValue, ValuePosition valuePosition = ValuePosition.auto, }) : drawBorder = drawBorder ?? borderColor != null && color != borderColor, diff --git a/pdf/lib/src/widgets/chart/line_chart.dart b/pdf/lib/src/widgets/chart/line_chart.dart index 7ce27cc6..a470ace7 100644 --- a/pdf/lib/src/widgets/chart/line_chart.dart +++ b/pdf/lib/src/widgets/chart/line_chart.dart @@ -16,7 +16,6 @@ import '../../../pdf.dart'; import '../geometry.dart'; -import '../page.dart'; import '../widget.dart'; import 'chart.dart'; import 'grid_cartesian.dart'; @@ -38,7 +37,7 @@ class LineDataSet extends PointDataSet { this.drawLine = true, this.lineColor, bool drawPoints = true, - BuildCallback? shape, + LegendBuildCallback? shape, Widget Function(Context context, T value)? buildValue, ValuePosition valuePosition = ValuePosition.auto, this.drawSurface = false, diff --git a/pdf/lib/src/widgets/chart/point_chart.dart b/pdf/lib/src/widgets/chart/point_chart.dart index c4ca4bbe..4572c346 100644 --- a/pdf/lib/src/widgets/chart/point_chart.dart +++ b/pdf/lib/src/widgets/chart/point_chart.dart @@ -17,12 +17,13 @@ import '../../../pdf.dart'; import '../basic.dart'; import '../geometry.dart'; -import '../page.dart'; import '../widget.dart'; import 'chart.dart'; enum ValuePosition { left, top, right, bottom, auto } +typedef LegendBuildCallback = Widget Function(Context context); + class PointChartValue extends ChartValue { const PointChartValue(this.x, this.y); final double x; @@ -56,7 +57,7 @@ class PointDataSet extends Dataset { final double pointSize; - final BuildCallback? shape; + final LegendBuildCallback? shape; final Widget Function(Context context, T value)? buildValue; @@ -94,7 +95,7 @@ class PointDataSet extends Dataset { } @override - void paintForeground(Context context) { + Future paintForeground(Context context) async { super.paintForeground(context); if (data.isEmpty) { @@ -120,7 +121,7 @@ class PointDataSet extends Dataset { Widget.draw( SizedBox.square( dimension: pointSize * 2, - child: shape!(context), + child: await shape!(context), ), offset: p, alignment: Alignment.center, diff --git a/pdf/lib/src/widgets/multi_page.dart b/pdf/lib/src/widgets/multi_page.dart index 04b85771..0ae82de1 100644 --- a/pdf/lib/src/widgets/multi_page.dart +++ b/pdf/lib/src/widgets/multi_page.dart @@ -216,7 +216,8 @@ class MultiPage extends Page { } @override - void generate(Document document, {bool insert = true, int? index}) { + Future generate(Document document, + {bool insert = true, int? index}) async { assert(pageFormat.width > 0 && pageFormat.width < double.infinity); assert(pageFormat.height > 0 && pageFormat.height < double.infinity); @@ -248,7 +249,7 @@ class MultiPage extends Page { if (pageTheme.textDirection != null) InheritedDirectionality(pageTheme.textDirection), ]); - final children = _buildList(baseContext); + final children = await _buildList(baseContext); WidgetContext? widgetContext; while (_index < children.length) { @@ -300,7 +301,7 @@ class MultiPage extends Page { )); if (header != null) { - final headerWidget = header!(context); + final headerWidget = await header!(context); headerWidget.layout(context, constraints, parentUsesSize: false); assert(headerWidget.box != null); @@ -308,7 +309,7 @@ class MultiPage extends Page { } if (footer != null) { - final footerWidget = footer!(context); + final footerWidget = await footer!(context); footerWidget.layout(context, constraints, parentUsesSize: false); assert(footerWidget.box != null); @@ -395,7 +396,7 @@ class MultiPage extends Page { } @override - void postProcess(Document document) { + Future postProcess(Document document) async { final _margin = resolvedMargin!; final _mustRotate = mustRotate; final pageHeight = _mustRotate ? pageFormat.width : pageFormat.height; @@ -412,7 +413,7 @@ class MultiPage extends Page { _mustRotate ? pageHeightMargin - _margin.left : _margin.bottom; if (pageTheme.buildBackground != null) { - final child = pageTheme.buildBackground!(page.context); + final child = await pageTheme.buildBackground!(page.context); child.layout(page.context, page.fullConstraints, parentUsesSize: false); assert(child.box != null); @@ -444,7 +445,7 @@ class MultiPage extends Page { } if (header != null) { - final headerWidget = header!(page.context); + final headerWidget = await header!(page.context); headerWidget.layout(page.context, page.constraints, parentUsesSize: false); assert(headerWidget.box != null); @@ -457,7 +458,7 @@ class MultiPage extends Page { } if (footer != null) { - final footerWidget = footer!(page.context); + final footerWidget = await footer!(page.context); footerWidget.layout(page.context, page.constraints, parentUsesSize: false); assert(footerWidget.box != null); @@ -580,7 +581,7 @@ class MultiPage extends Page { } if (pageTheme.buildForeground != null) { - final child = pageTheme.buildForeground!(page.context); + final child = await pageTheme.buildForeground!(page.context); child.layout(page.context, page.fullConstraints, parentUsesSize: false); assert(child.box != null); diff --git a/pdf/lib/src/widgets/page.dart b/pdf/lib/src/widgets/page.dart index 7b34184e..5532760f 100644 --- a/pdf/lib/src/widgets/page.dart +++ b/pdf/lib/src/widgets/page.dart @@ -14,6 +14,7 @@ * limitations under the License. */ +import 'dart:async'; import 'dart:math' as math; import 'package:meta/meta.dart'; @@ -28,8 +29,8 @@ import 'text_style.dart'; import 'theme.dart'; import 'widget.dart'; -typedef BuildCallback = Widget Function(Context context); -typedef BuildListCallback = List Function(Context context); +typedef BuildCallback = FutureOr Function(Context context); +typedef BuildListCallback = FutureOr> Function(Context context); enum PageOrientation { natural, landscape, portrait } @@ -112,7 +113,7 @@ class Page { } } - void postProcess(Document document) { + Future postProcess(Document document) async { final canvas = _pdfPage!.getGraphics(); canvas.reset(); final _margin = resolvedMargin; @@ -139,7 +140,7 @@ class Page { Widget? content; Widget? foreground; - content = _build(context); + content = await _build(context); final size = layout(content, context, constraints); @@ -156,12 +157,12 @@ class Page { } if (pageTheme.buildBackground != null) { - background = pageTheme.buildBackground!(context); + background = await pageTheme.buildBackground!(context); layout(background, context, constraints); } if (pageTheme.buildForeground != null) { - foreground = pageTheme.buildForeground!(context); + foreground = await pageTheme.buildForeground!(context); layout(foreground, context, constraints); } diff --git a/pdf/lib/src/widgets/widget.dart b/pdf/lib/src/widgets/widget.dart index 0751ac68..63b7d4e9 100644 --- a/pdf/lib/src/widgets/widget.dart +++ b/pdf/lib/src/widgets/widget.dart @@ -368,10 +368,13 @@ class InheritedWidget extends SingleChildWidget { Widget? _child; @override - void layout(Context context, BoxConstraints constraints, - {bool parentUsesSize = false}) { + void layout( + Context context, + BoxConstraints constraints, { + bool parentUsesSize = false, + }) async { _context = inherited != null ? context.inheritFrom(inherited!) : context; - _child = build!(_context!); + _child = await build!(_context!); super.layout(_context!, constraints); } @@ -394,14 +397,17 @@ class DelayedWidget extends SingleChildWidget { Widget? _child; @override - void layout(Context context, BoxConstraints constraints, - {bool parentUsesSize = false}) { - _child = build(context); + Future layout( + Context context, + BoxConstraints constraints, { + bool parentUsesSize = false, + }) async { + _child = await build(context); super.layout(context, constraints); } - void delayedPaint(Context context) { - _child = build(context); + Future delayedPaint(Context context) async { + _child = await build(context); child!.layout( context, BoxConstraints.tight(box!.size),