Showing
8 changed files
with
177 additions
and
127 deletions
@@ -38,13 +38,13 @@ class ChartLegend extends StatelessWidget { | @@ -38,13 +38,13 @@ class ChartLegend extends StatelessWidget { | ||
38 | 38 | ||
39 | final TextStyle? textStyle; | 39 | final TextStyle? textStyle; |
40 | 40 | ||
41 | - final Alignment position; | 41 | + final AlignmentGeometry position; |
42 | 42 | ||
43 | final Axis direction; | 43 | final Axis direction; |
44 | 44 | ||
45 | final BoxDecoration? decoration; | 45 | final BoxDecoration? decoration; |
46 | 46 | ||
47 | - final EdgeInsets padding; | 47 | + final EdgeInsetsGeometry padding; |
48 | 48 | ||
49 | Widget _buildLegend(Context context, Dataset dataset) { | 49 | Widget _buildLegend(Context context, Dataset dataset) { |
50 | final style = Theme.of(context).defaultTextStyle.merge(textStyle); | 50 | final style = Theme.of(context).defaultTextStyle.merge(textStyle); |
@@ -75,9 +75,9 @@ class Container extends StatelessWidget { | @@ -75,9 +75,9 @@ class Container extends StatelessWidget { | ||
75 | 75 | ||
76 | final Widget? child; | 76 | final Widget? child; |
77 | 77 | ||
78 | - final Alignment? alignment; | 78 | + final AlignmentGeometry? alignment; |
79 | 79 | ||
80 | - final EdgeInsets? padding; | 80 | + final EdgeInsetsGeometry? padding; |
81 | 81 | ||
82 | /// The decoration to paint behind the [child]. | 82 | /// The decoration to paint behind the [child]. |
83 | final BoxDecoration? decoration; | 83 | final BoxDecoration? decoration; |
@@ -89,7 +89,7 @@ class Container extends StatelessWidget { | @@ -89,7 +89,7 @@ class Container extends StatelessWidget { | ||
89 | final BoxConstraints? constraints; | 89 | final BoxConstraints? constraints; |
90 | 90 | ||
91 | /// Empty space to surround the [decoration] and [child]. | 91 | /// Empty space to surround the [decoration] and [child]. |
92 | - final EdgeInsets? margin; | 92 | + final EdgeInsetsGeometry? margin; |
93 | 93 | ||
94 | /// The transformation matrix to apply before painting the container. | 94 | /// The transformation matrix to apply before painting the container. |
95 | final Matrix4? transform; | 95 | final Matrix4? transform; |
@@ -56,9 +56,9 @@ class Header extends StatelessWidget { | @@ -56,9 +56,9 @@ class Header extends StatelessWidget { | ||
56 | 56 | ||
57 | final BoxDecoration? decoration; | 57 | final BoxDecoration? decoration; |
58 | 58 | ||
59 | - final EdgeInsets? margin; | 59 | + final EdgeInsetsGeometry? margin; |
60 | 60 | ||
61 | - final EdgeInsets? padding; | 61 | + final EdgeInsetsGeometry? padding; |
62 | 62 | ||
63 | final TextStyle? textStyle; | 63 | final TextStyle? textStyle; |
64 | 64 | ||
@@ -190,9 +190,9 @@ class Paragraph extends StatelessWidget { | @@ -190,9 +190,9 @@ class Paragraph extends StatelessWidget { | ||
190 | 190 | ||
191 | final TextStyle? style; | 191 | final TextStyle? style; |
192 | 192 | ||
193 | - final EdgeInsets margin; | 193 | + final EdgeInsetsGeometry margin; |
194 | 194 | ||
195 | - final EdgeInsets? padding; | 195 | + final EdgeInsetsGeometry? padding; |
196 | 196 | ||
197 | @override | 197 | @override |
198 | Widget build(Context context) { | 198 | Widget build(Context context) { |
@@ -232,11 +232,11 @@ class Bullet extends StatelessWidget { | @@ -232,11 +232,11 @@ class Bullet extends StatelessWidget { | ||
232 | 232 | ||
233 | final TextStyle? style; | 233 | final TextStyle? style; |
234 | 234 | ||
235 | - final EdgeInsets margin; | 235 | + final EdgeInsetsGeometry margin; |
236 | 236 | ||
237 | - final EdgeInsets? padding; | 237 | + final EdgeInsetsGeometry? padding; |
238 | 238 | ||
239 | - final EdgeInsets bulletMargin; | 239 | + final EdgeInsetsGeometry bulletMargin; |
240 | 240 | ||
241 | final double bulletSize; | 241 | final double bulletSize; |
242 | 242 |
@@ -649,7 +649,7 @@ class ListView extends StatelessWidget { | @@ -649,7 +649,7 @@ class ListView extends StatelessWidget { | ||
649 | super(); | 649 | super(); |
650 | 650 | ||
651 | final Axis direction; | 651 | final Axis direction; |
652 | - final EdgeInsets? padding; | 652 | + final EdgeInsetsGeometry? padding; |
653 | final double? spacing; | 653 | final double? spacing; |
654 | final bool reverse; | 654 | final bool reverse; |
655 | final IndexedWidgetBuilder? itemBuilder; | 655 | final IndexedWidgetBuilder? itemBuilder; |
@@ -15,9 +15,7 @@ | @@ -15,9 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | 16 | ||
17 | import '../../pdf.dart'; | 17 | import '../../pdf.dart'; |
18 | -import 'box_border.dart'; | ||
19 | -import 'geometry.dart'; | ||
20 | -import 'widget.dart'; | 18 | +import '../../widgets.dart'; |
21 | 19 | ||
22 | /// A widget that draws a rectilinear grid of lines. | 20 | /// A widget that draws a rectilinear grid of lines. |
23 | /// The grid is drawn over the [child] widget. | 21 | /// The grid is drawn over the [child] widget. |
@@ -187,7 +185,7 @@ class GridPaper extends SingleChildWidget { | @@ -187,7 +185,7 @@ class GridPaper extends SingleChildWidget { | ||
187 | final int verticalSubdivisions; | 185 | final int verticalSubdivisions; |
188 | 186 | ||
189 | /// The margin to apply to the horizontal and vertical lines | 187 | /// The margin to apply to the horizontal and vertical lines |
190 | - final EdgeInsets margin; | 188 | + final EdgeInsetsGeometry margin; |
191 | 189 | ||
192 | final int horizontalOffset; | 190 | final int horizontalOffset; |
193 | 191 | ||
@@ -202,12 +200,14 @@ class GridPaper extends SingleChildWidget { | @@ -202,12 +200,14 @@ class GridPaper extends SingleChildWidget { | ||
202 | @override | 200 | @override |
203 | void layout(Context context, BoxConstraints constraints, | 201 | void layout(Context context, BoxConstraints constraints, |
204 | {bool parentUsesSize = false}) { | 202 | {bool parentUsesSize = false}) { |
203 | + | ||
204 | + final resolvedMargin = margin.resolve(Directionality.of(context)); | ||
205 | box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest); | 205 | box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest); |
206 | if (child != null) { | 206 | if (child != null) { |
207 | if (constraints.hasBoundedWidth && constraints.hasBoundedHeight) { | 207 | if (constraints.hasBoundedWidth && constraints.hasBoundedHeight) { |
208 | final childConstraints = BoxConstraints( | 208 | final childConstraints = BoxConstraints( |
209 | - maxWidth: constraints.maxWidth - margin.horizontal, | ||
210 | - maxHeight: constraints.maxHeight - margin.vertical, | 209 | + maxWidth: constraints.maxWidth - resolvedMargin.horizontal, |
210 | + maxHeight: constraints.maxHeight - resolvedMargin.vertical, | ||
211 | ); | 211 | ); |
212 | child!.layout(context, childConstraints, parentUsesSize: false); | 212 | child!.layout(context, childConstraints, parentUsesSize: false); |
213 | } else { | 213 | } else { |
@@ -216,7 +216,7 @@ class GridPaper extends SingleChildWidget { | @@ -216,7 +216,7 @@ class GridPaper extends SingleChildWidget { | ||
216 | 216 | ||
217 | assert(child!.box != null); | 217 | assert(child!.box != null); |
218 | child!.box = PdfRect.fromPoints( | 218 | child!.box = PdfRect.fromPoints( |
219 | - PdfPoint(margin.left, box!.top - margin.top - child!.box!.height), | 219 | + PdfPoint(resolvedMargin.left, box!.top - resolvedMargin.top - child!.box!.height), |
220 | child!.box!.size); | 220 | child!.box!.size); |
221 | } | 221 | } |
222 | } | 222 | } |
@@ -225,7 +225,7 @@ class GridPaper extends SingleChildWidget { | @@ -225,7 +225,7 @@ class GridPaper extends SingleChildWidget { | ||
225 | void paint(Context context) { | 225 | void paint(Context context) { |
226 | super.paint(context); | 226 | super.paint(context); |
227 | paintChild(context); | 227 | paintChild(context); |
228 | - | 228 | + final resolvedMargin = margin.resolve(Directionality.of(context)); |
229 | context.canvas.saveContext(); | 229 | context.canvas.saveContext(); |
230 | context.canvas.setGraphicState(PdfGraphicState(opacity: opacity)); | 230 | context.canvas.setGraphicState(PdfGraphicState(opacity: opacity)); |
231 | context.canvas.setStrokeColor(horizontalColor); | 231 | context.canvas.setStrokeColor(horizontalColor); |
@@ -236,8 +236,8 @@ class GridPaper extends SingleChildWidget { | @@ -236,8 +236,8 @@ class GridPaper extends SingleChildWidget { | ||
236 | final allHorizontalDivisions = | 236 | final allHorizontalDivisions = |
237 | (horizontalDivisions * horizontalSubdivisions).toDouble(); | 237 | (horizontalDivisions * horizontalSubdivisions).toDouble(); |
238 | var n = horizontalOffset; | 238 | var n = horizontalOffset; |
239 | - for (var x = box!.left + margin.left; | ||
240 | - x <= box!.right - margin.right; | 239 | + for (var x = box!.left + resolvedMargin.left; |
240 | + x <= box!.right - resolvedMargin.right; | ||
241 | x += horizontalInterval / allHorizontalDivisions) { | 241 | x += horizontalInterval / allHorizontalDivisions) { |
242 | context.canvas | 242 | context.canvas |
243 | ..setLineWidth((n % (horizontalSubdivisions * horizontalDivisions) == 0) | 243 | ..setLineWidth((n % (horizontalSubdivisions * horizontalDivisions) == 0) |
@@ -254,8 +254,8 @@ class GridPaper extends SingleChildWidget { | @@ -254,8 +254,8 @@ class GridPaper extends SingleChildWidget { | ||
254 | final allVerticalDivisions = | 254 | final allVerticalDivisions = |
255 | (verticalDivisions * verticalSubdivisions).toDouble(); | 255 | (verticalDivisions * verticalSubdivisions).toDouble(); |
256 | n = verticalOffset; | 256 | n = verticalOffset; |
257 | - for (var y = box!.top - margin.top; | ||
258 | - y >= box!.bottom + margin.bottom; | 257 | + for (var y = box!.top - resolvedMargin.top; |
258 | + y >= box!.bottom + resolvedMargin.bottom; | ||
259 | y -= verticalInterval / allVerticalDivisions) { | 259 | y -= verticalInterval / allVerticalDivisions) { |
260 | context.canvas | 260 | context.canvas |
261 | ..setLineWidth((n % (verticalSubdivisions * verticalDivisions) == 0) | 261 | ..setLineWidth((n % (verticalSubdivisions * verticalDivisions) == 0) |
@@ -273,7 +273,7 @@ class GridPaper extends SingleChildWidget { | @@ -273,7 +273,7 @@ class GridPaper extends SingleChildWidget { | ||
273 | context.canvas | 273 | context.canvas |
274 | ..setStrokeColor(border.left.color) | 274 | ..setStrokeColor(border.left.color) |
275 | ..setLineWidth(border.left.width) | 275 | ..setLineWidth(border.left.width) |
276 | - ..drawLine(box!.left + margin.left, box!.top, box!.left + margin.left, | 276 | + ..drawLine(box!.left + resolvedMargin.left, box!.top, box!.left + resolvedMargin.left, |
277 | box!.bottom) | 277 | box!.bottom) |
278 | ..strokePath(); | 278 | ..strokePath(); |
279 | border.left.style.unsetStyle(context); | 279 | border.left.style.unsetStyle(context); |
@@ -283,8 +283,8 @@ class GridPaper extends SingleChildWidget { | @@ -283,8 +283,8 @@ class GridPaper extends SingleChildWidget { | ||
283 | context.canvas | 283 | context.canvas |
284 | ..setStrokeColor(border.right.color) | 284 | ..setStrokeColor(border.right.color) |
285 | ..setLineWidth(border.right.width) | 285 | ..setLineWidth(border.right.width) |
286 | - ..drawLine(box!.right - margin.right, box!.top, | ||
287 | - box!.right - margin.right, box!.bottom) | 286 | + ..drawLine(box!.right - resolvedMargin.right, box!.top, |
287 | + box!.right - resolvedMargin.right, box!.bottom) | ||
288 | ..strokePath(); | 288 | ..strokePath(); |
289 | border.right.style.unsetStyle(context); | 289 | border.right.style.unsetStyle(context); |
290 | } | 290 | } |
@@ -294,7 +294,7 @@ class GridPaper extends SingleChildWidget { | @@ -294,7 +294,7 @@ class GridPaper extends SingleChildWidget { | ||
294 | ..setStrokeColor(border.top.color) | 294 | ..setStrokeColor(border.top.color) |
295 | ..setLineWidth(border.top.width) | 295 | ..setLineWidth(border.top.width) |
296 | ..drawLine( | 296 | ..drawLine( |
297 | - box!.left, box!.top - margin.top, box!.right, box!.top - margin.top) | 297 | + box!.left, box!.top - resolvedMargin.top, box!.right, box!.top - resolvedMargin.top) |
298 | ..strokePath(); | 298 | ..strokePath(); |
299 | border.top.style.unsetStyle(context); | 299 | border.top.style.unsetStyle(context); |
300 | } | 300 | } |
@@ -303,8 +303,8 @@ class GridPaper extends SingleChildWidget { | @@ -303,8 +303,8 @@ class GridPaper extends SingleChildWidget { | ||
303 | context.canvas | 303 | context.canvas |
304 | ..setStrokeColor(border.bottom.color) | 304 | ..setStrokeColor(border.bottom.color) |
305 | ..setLineWidth(border.bottom.width) | 305 | ..setLineWidth(border.bottom.width) |
306 | - ..drawLine(box!.left, box!.bottom + margin.bottom, box!.right, | ||
307 | - box!.bottom + margin.bottom) | 306 | + ..drawLine(box!.left, box!.bottom + resolvedMargin.bottom, box!.right, |
307 | + box!.bottom + resolvedMargin.bottom) | ||
308 | ..strokePath(); | 308 | ..strokePath(); |
309 | border.bottom.style.unsetStyle(context); | 309 | border.bottom.style.unsetStyle(context); |
310 | } | 310 | } |
@@ -16,12 +16,14 @@ | @@ -16,12 +16,14 @@ | ||
16 | 16 | ||
17 | import 'dart:math' as math; | 17 | import 'dart:math' as math; |
18 | 18 | ||
19 | +import 'package:pdf/widgets.dart'; | ||
19 | import 'package:vector_math/vector_math_64.dart'; | 20 | import 'package:vector_math/vector_math_64.dart'; |
20 | 21 | ||
21 | import '../../pdf.dart'; | 22 | import '../../pdf.dart'; |
22 | import 'flex.dart'; | 23 | import 'flex.dart'; |
23 | import 'geometry.dart'; | 24 | import 'geometry.dart'; |
24 | import 'multi_page.dart'; | 25 | import 'multi_page.dart'; |
26 | +import 'text_style.dart'; | ||
25 | import 'widget.dart'; | 27 | import 'widget.dart'; |
26 | 28 | ||
27 | class GridViewContext extends WidgetContext { | 29 | class GridViewContext extends WidgetContext { |
@@ -45,8 +47,7 @@ class GridViewContext extends WidgetContext { | @@ -45,8 +47,7 @@ class GridViewContext extends WidgetContext { | ||
45 | } | 47 | } |
46 | 48 | ||
47 | @override | 49 | @override |
48 | - String toString() => | ||
49 | - '$runtimeType first:$firstChild last:$lastChild size:${childCrossAxis}x$childMainAxis'; | 50 | + String toString() => '$runtimeType first:$firstChild last:$lastChild size:${childCrossAxis}x$childMainAxis'; |
50 | } | 51 | } |
51 | 52 | ||
52 | class GridView extends MultiChildWidget with SpanningWidget { | 53 | class GridView extends MultiChildWidget with SpanningWidget { |
@@ -61,7 +62,7 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -61,7 +62,7 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
61 | : super(children: children); | 62 | : super(children: children); |
62 | 63 | ||
63 | final Axis direction; | 64 | final Axis direction; |
64 | - final EdgeInsets padding; | 65 | + final EdgeInsetsGeometry padding; |
65 | final int crossAxisCount; | 66 | final int crossAxisCount; |
66 | final double mainAxisSpacing; | 67 | final double mainAxisSpacing; |
67 | final double crossAxisSpacing; | 68 | final double crossAxisSpacing; |
@@ -72,8 +73,7 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -72,8 +73,7 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
72 | int? _mainAxisCount; | 73 | int? _mainAxisCount; |
73 | 74 | ||
74 | @override | 75 | @override |
75 | - void layout(Context context, BoxConstraints constraints, | ||
76 | - {bool parentUsesSize = false}) { | 76 | + void layout(Context context, BoxConstraints constraints, {bool parentUsesSize = false}) { |
77 | if (children.isEmpty) { | 77 | if (children.isEmpty) { |
78 | box = PdfRect.zero; | 78 | box = PdfRect.zero; |
79 | return; | 79 | return; |
@@ -81,13 +81,13 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -81,13 +81,13 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
81 | 81 | ||
82 | assert(() { | 82 | assert(() { |
83 | if (constraints.maxHeight.isInfinite && childAspectRatio.isInfinite) { | 83 | if (constraints.maxHeight.isInfinite && childAspectRatio.isInfinite) { |
84 | - print( | ||
85 | - 'Unable to calculate the GridView dimensions. Please set the height constraints or childAspectRatio.'); | 84 | + print('Unable to calculate the GridView dimensions. Please set the height constraints or childAspectRatio.'); |
86 | return false; | 85 | return false; |
87 | } | 86 | } |
88 | return true; | 87 | return true; |
89 | }()); | 88 | }()); |
90 | - | 89 | + final textDirection = Directionality.of(context); |
90 | + final resolvedPadding = padding.resolve(textDirection); | ||
91 | late double mainAxisExtent; | 91 | late double mainAxisExtent; |
92 | late double crossAxisExtent; | 92 | late double crossAxisExtent; |
93 | switch (direction) { | 93 | switch (direction) { |
@@ -102,25 +102,19 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -102,25 +102,19 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
102 | } | 102 | } |
103 | 103 | ||
104 | if (constraints.maxHeight.isInfinite || _mainAxisCount == null) { | 104 | if (constraints.maxHeight.isInfinite || _mainAxisCount == null) { |
105 | - _mainAxisCount = | ||
106 | - ((children.length - _context.firstChild) / crossAxisCount).ceil(); | 105 | + _mainAxisCount = ((children.length - _context.firstChild) / crossAxisCount).ceil(); |
107 | 106 | ||
108 | - _context.childCrossAxis = crossAxisExtent / crossAxisCount - | ||
109 | - (crossAxisSpacing * (crossAxisCount - 1) / crossAxisCount); | 107 | + _context.childCrossAxis = |
108 | + crossAxisExtent / crossAxisCount - (crossAxisSpacing * (crossAxisCount - 1) / crossAxisCount); | ||
110 | 109 | ||
111 | - _context.childMainAxis = math.min( | ||
112 | - _context.childCrossAxis! * childAspectRatio, | ||
113 | - mainAxisExtent / _mainAxisCount! - | ||
114 | - (mainAxisSpacing * (_mainAxisCount! - 1) / _mainAxisCount!)); | 110 | + _context.childMainAxis = math.min(_context.childCrossAxis! * childAspectRatio, |
111 | + mainAxisExtent / _mainAxisCount! - (mainAxisSpacing * (_mainAxisCount! - 1) / _mainAxisCount!)); | ||
115 | 112 | ||
116 | if (_context.childCrossAxis!.isInfinite) { | 113 | if (_context.childCrossAxis!.isInfinite) { |
117 | - throw Exception( | ||
118 | - 'Unable to calculate child height as the height constraint is infinite.'); | 114 | + throw Exception('Unable to calculate child height as the height constraint is infinite.'); |
119 | } | 115 | } |
120 | } else { | 116 | } else { |
121 | - _mainAxisCount = ((mainAxisExtent + mainAxisSpacing) / | ||
122 | - (mainAxisSpacing + _context.childMainAxis!)) | ||
123 | - .floor(); | 117 | + _mainAxisCount = ((mainAxisExtent + mainAxisSpacing) / (mainAxisSpacing + _context.childMainAxis!)).floor(); |
124 | 118 | ||
125 | if (_mainAxisCount! < 0) { | 119 | if (_mainAxisCount! < 0) { |
126 | // Not enough space to put one line, try to ask for more space. | 120 | // Not enough space to put one line, try to ask for more space. |
@@ -128,28 +122,22 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -128,28 +122,22 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
128 | } | 122 | } |
129 | } | 123 | } |
130 | 124 | ||
131 | - final totalMain = | ||
132 | - (_context.childMainAxis! + mainAxisSpacing) * _mainAxisCount! - | ||
133 | - mainAxisSpacing; | ||
134 | - final totalCross = | ||
135 | - (_context.childCrossAxis! + crossAxisSpacing) * crossAxisCount - | ||
136 | - crossAxisSpacing; | 125 | + final totalMain = (_context.childMainAxis! + mainAxisSpacing) * _mainAxisCount! - mainAxisSpacing; |
126 | + final totalCross = (_context.childCrossAxis! + crossAxisSpacing) * crossAxisCount - crossAxisSpacing; | ||
137 | 127 | ||
138 | - final startX = padding.left; | 128 | + final startX = resolvedPadding.left; |
139 | const startY = 0.0; | 129 | const startY = 0.0; |
140 | late double mainAxis; | 130 | late double mainAxis; |
141 | late double crossAxis; | 131 | late double crossAxis; |
142 | BoxConstraints? innerConstraints; | 132 | BoxConstraints? innerConstraints; |
143 | switch (direction) { | 133 | switch (direction) { |
144 | case Axis.vertical: | 134 | case Axis.vertical: |
145 | - innerConstraints = BoxConstraints.tightFor( | ||
146 | - width: _context.childCrossAxis, height: _context.childMainAxis); | 135 | + innerConstraints = BoxConstraints.tightFor(width: _context.childCrossAxis, height: _context.childMainAxis); |
147 | crossAxis = startX; | 136 | crossAxis = startX; |
148 | mainAxis = startY; | 137 | mainAxis = startY; |
149 | break; | 138 | break; |
150 | case Axis.horizontal: | 139 | case Axis.horizontal: |
151 | - innerConstraints = BoxConstraints.tightFor( | ||
152 | - width: _context.childMainAxis, height: _context.childCrossAxis); | 140 | + innerConstraints = BoxConstraints.tightFor(width: _context.childMainAxis, height: _context.childCrossAxis); |
153 | mainAxis = startX; | 141 | mainAxis = startX; |
154 | crossAxis = startY; | 142 | crossAxis = startY; |
155 | break; | 143 | break; |
@@ -158,10 +146,9 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -158,10 +146,9 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
158 | var c = 0; | 146 | var c = 0; |
159 | _context.lastChild = _context.firstChild; | 147 | _context.lastChild = _context.firstChild; |
160 | 148 | ||
149 | + final isRtl = textDirection == TextDirection.rtl; | ||
161 | for (final child in children.sublist( | 150 | for (final child in children.sublist( |
162 | - _context.firstChild, | ||
163 | - math.min(children.length, | ||
164 | - _context.firstChild + crossAxisCount * _mainAxisCount!))) { | 151 | + _context.firstChild, math.min(children.length, _context.firstChild + crossAxisCount * _mainAxisCount!))) { |
165 | child.layout(context, innerConstraints); | 152 | child.layout(context, innerConstraints); |
166 | assert(child.box != null); | 153 | assert(child.box != null); |
167 | 154 | ||
@@ -169,21 +156,26 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -169,21 +156,26 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
169 | case Axis.vertical: | 156 | case Axis.vertical: |
170 | child.box = PdfRect.fromPoints( | 157 | child.box = PdfRect.fromPoints( |
171 | PdfPoint( | 158 | PdfPoint( |
172 | - (_context.childCrossAxis! - child.box!.width) / 2.0 + | ||
173 | - crossAxis, | ||
174 | - totalMain + | ||
175 | - padding.bottom - | ||
176 | - (_context.childMainAxis! - child.box!.height) / 2.0 - | ||
177 | - mainAxis - | ||
178 | - child.box!.height), | 159 | + isRtl |
160 | + ? (_context.childCrossAxis! + child.box!.width - crossAxis) | ||
161 | + : (_context.childCrossAxis! - child.box!.width) / 2.0 + crossAxis, | ||
162 | + totalMain + | ||
163 | + resolvedPadding.bottom - | ||
164 | + (_context.childMainAxis! - child.box!.height) / 2.0 - | ||
165 | + mainAxis - | ||
166 | + child.box!.height, | ||
167 | + ), | ||
179 | child.box!.size); | 168 | child.box!.size); |
169 | + | ||
180 | break; | 170 | break; |
181 | case Axis.horizontal: | 171 | case Axis.horizontal: |
182 | child.box = PdfRect.fromPoints( | 172 | child.box = PdfRect.fromPoints( |
183 | PdfPoint( | 173 | PdfPoint( |
184 | - (_context.childMainAxis! - child.box!.width) / 2.0 + mainAxis, | 174 | + isRtl |
175 | + ? totalMain - (child.box!.width + mainAxis) | ||
176 | + : (_context.childMainAxis! - child.box!.width) / 2.0 + mainAxis, | ||
185 | totalCross + | 177 | totalCross + |
186 | - padding.bottom - | 178 | + resolvedPadding.bottom - |
187 | (_context.childCrossAxis! - child.box!.height) / 2.0 - | 179 | (_context.childCrossAxis! - child.box!.height) / 2.0 - |
188 | crossAxis - | 180 | crossAxis - |
189 | child.box!.height), | 181 | child.box!.height), |
@@ -216,14 +208,10 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -216,14 +208,10 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
216 | 208 | ||
217 | switch (direction) { | 209 | switch (direction) { |
218 | case Axis.vertical: | 210 | case Axis.vertical: |
219 | - box = constraints.constrainRect( | ||
220 | - width: totalCross + padding.horizontal, | ||
221 | - height: totalMain + padding.vertical); | 211 | + box = constraints.constrainRect(width: totalCross + padding.horizontal, height: totalMain + padding.vertical); |
222 | break; | 212 | break; |
223 | case Axis.horizontal: | 213 | case Axis.horizontal: |
224 | - box = constraints.constrainRect( | ||
225 | - width: totalMain + padding.horizontal, | ||
226 | - height: totalCross + padding.vertical); | 214 | + box = constraints.constrainRect(width: totalMain + padding.horizontal, height: totalCross + padding.vertical); |
227 | break; | 215 | break; |
228 | } | 216 | } |
229 | } | 217 | } |
@@ -235,6 +223,7 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -235,6 +223,7 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
235 | if (children.isEmpty) { | 223 | if (children.isEmpty) { |
236 | return; | 224 | return; |
237 | } | 225 | } |
226 | + final resolvedPadding = padding.resolve(Directionality.of(context)); | ||
238 | 227 | ||
239 | context.canvas | 228 | context.canvas |
240 | ..setFillColor(PdfColors.lime) | 229 | ..setFillColor(PdfColors.lime) |
@@ -242,35 +231,26 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -242,35 +231,26 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
242 | ..lineTo(box!.right, box!.bottom) | 231 | ..lineTo(box!.right, box!.bottom) |
243 | ..lineTo(box!.right, box!.top) | 232 | ..lineTo(box!.right, box!.top) |
244 | ..lineTo(box!.left, box!.top) | 233 | ..lineTo(box!.left, box!.top) |
245 | - ..moveTo(box!.left + padding.left, box!.bottom + padding.bottom) | ||
246 | - ..lineTo(box!.left + padding.left, box!.top - padding.top) | ||
247 | - ..lineTo(box!.right - padding.right, box!.top - padding.top) | ||
248 | - ..lineTo(box!.right - padding.right, box!.bottom + padding.bottom) | 234 | + ..moveTo(box!.left + resolvedPadding.left, box!.bottom + resolvedPadding.bottom) |
235 | + ..lineTo(box!.left + resolvedPadding.left, box!.top - resolvedPadding.top) | ||
236 | + ..lineTo(box!.right - resolvedPadding.right, box!.top - resolvedPadding.top) | ||
237 | + ..lineTo(box!.right - resolvedPadding.right, box!.bottom + resolvedPadding.bottom) | ||
249 | ..fillPath(); | 238 | ..fillPath(); |
250 | 239 | ||
251 | for (var c = 1; c < crossAxisCount; c++) { | 240 | for (var c = 1; c < crossAxisCount; c++) { |
252 | switch (direction) { | 241 | switch (direction) { |
253 | case Axis.vertical: | 242 | case Axis.vertical: |
254 | context.canvas | 243 | context.canvas |
255 | - ..drawRect( | ||
256 | - box!.left + | ||
257 | - padding.left + | ||
258 | - (_context.childCrossAxis! + crossAxisSpacing) * c - | ||
259 | - crossAxisSpacing, | ||
260 | - box!.bottom + padding.bottom, | ||
261 | - math.max(crossAxisSpacing, 1), | ||
262 | - box!.height - padding.vertical) | 244 | + ..drawRect(box!.left + resolvedPadding.left + (_context.childCrossAxis! + crossAxisSpacing) * c - crossAxisSpacing, |
245 | + box!.bottom + resolvedPadding.bottom, math.max(crossAxisSpacing, 1), box!.height - resolvedPadding.vertical) | ||
263 | ..fillPath(); | 246 | ..fillPath(); |
264 | break; | 247 | break; |
265 | case Axis.horizontal: | 248 | case Axis.horizontal: |
266 | context.canvas | 249 | context.canvas |
267 | ..drawRect( | 250 | ..drawRect( |
268 | - box!.left + padding.left, | ||
269 | - box!.bottom + | ||
270 | - padding.bottom + | ||
271 | - (_context.childCrossAxis! + crossAxisSpacing) * c - | ||
272 | - crossAxisSpacing, | ||
273 | - box!.width - padding.horizontal, | 251 | + box!.left + resolvedPadding.left, |
252 | + box!.bottom + resolvedPadding.bottom + (_context.childCrossAxis! + crossAxisSpacing) * c - crossAxisSpacing, | ||
253 | + box!.width - resolvedPadding.horizontal, | ||
274 | math.max(crossAxisSpacing, 1)) | 254 | math.max(crossAxisSpacing, 1)) |
275 | ..fillPath(); | 255 | ..fillPath(); |
276 | break; | 256 | break; |
@@ -282,25 +262,16 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -282,25 +262,16 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
282 | case Axis.vertical: | 262 | case Axis.vertical: |
283 | context.canvas | 263 | context.canvas |
284 | ..drawRect( | 264 | ..drawRect( |
285 | - box!.left + padding.left, | ||
286 | - box!.bottom + | ||
287 | - padding.bottom + | ||
288 | - (_context.childMainAxis! + mainAxisSpacing) * c - | ||
289 | - mainAxisSpacing, | ||
290 | - box!.width - padding.horizontal, | 265 | + box!.left + resolvedPadding.left, |
266 | + box!.bottom + resolvedPadding.bottom + (_context.childMainAxis! + mainAxisSpacing) * c - mainAxisSpacing, | ||
267 | + box!.width - resolvedPadding.horizontal, | ||
291 | math.max(mainAxisSpacing, 1)) | 268 | math.max(mainAxisSpacing, 1)) |
292 | ..fillPath(); | 269 | ..fillPath(); |
293 | break; | 270 | break; |
294 | case Axis.horizontal: | 271 | case Axis.horizontal: |
295 | context.canvas | 272 | context.canvas |
296 | - ..drawRect( | ||
297 | - box!.left + | ||
298 | - padding.left + | ||
299 | - (_context.childMainAxis! + mainAxisSpacing) * c - | ||
300 | - mainAxisSpacing, | ||
301 | - box!.bottom + padding.bottom, | ||
302 | - math.max(mainAxisSpacing, 1), | ||
303 | - box!.height - padding.vertical) | 273 | + ..drawRect(box!.left + resolvedPadding.left + (_context.childMainAxis! + mainAxisSpacing) * c - mainAxisSpacing, |
274 | + box!.bottom + resolvedPadding.bottom, math.max(mainAxisSpacing, 1), box!.height - resolvedPadding.vertical) | ||
304 | ..fillPath(); | 275 | ..fillPath(); |
305 | break; | 276 | break; |
306 | } | 277 | } |
@@ -317,8 +288,7 @@ class GridView extends MultiChildWidget with SpanningWidget { | @@ -317,8 +288,7 @@ class GridView extends MultiChildWidget with SpanningWidget { | ||
317 | ..saveContext() | 288 | ..saveContext() |
318 | ..setTransform(mat); | 289 | ..setTransform(mat); |
319 | 290 | ||
320 | - for (var child | ||
321 | - in children.sublist(_context.firstChild, _context.lastChild)) { | 291 | + for (var child in children.sublist(_context.firstChild, _context.lastChild)) { |
322 | child.paint(context); | 292 | child.paint(context); |
323 | } | 293 | } |
324 | context.canvas.restoreContext(); | 294 | context.canvas.restoreContext(); |
@@ -38,7 +38,7 @@ mixin TableHelper { | @@ -38,7 +38,7 @@ mixin TableHelper { | ||
38 | static Table fromTextArray({ | 38 | static Table fromTextArray({ |
39 | Context? context, | 39 | Context? context, |
40 | required List<List<dynamic>> data, | 40 | required List<List<dynamic>> data, |
41 | - EdgeInsets cellPadding = const EdgeInsets.all(5), | 41 | + EdgeInsetsGeometry cellPadding = const EdgeInsets.all(5), |
42 | double cellHeight = 0, | 42 | double cellHeight = 0, |
43 | Alignment cellAlignment = Alignment.topLeft, | 43 | Alignment cellAlignment = Alignment.topLeft, |
44 | Map<int, Alignment>? cellAlignments, | 44 | Map<int, Alignment>? cellAlignments, |
@@ -48,7 +48,7 @@ mixin TableHelper { | @@ -48,7 +48,7 @@ mixin TableHelper { | ||
48 | OnCellDecoration? cellDecoration, | 48 | OnCellDecoration? cellDecoration, |
49 | int headerCount = 1, | 49 | int headerCount = 1, |
50 | List<dynamic>? headers, | 50 | List<dynamic>? headers, |
51 | - EdgeInsets? headerPadding, | 51 | + EdgeInsetsGeometry? headerPadding, |
52 | double? headerHeight, | 52 | double? headerHeight, |
53 | Alignment headerAlignment = Alignment.center, | 53 | Alignment headerAlignment = Alignment.center, |
54 | Map<int, Alignment>? headerAlignments, | 54 | Map<int, Alignment>? headerAlignments, |
@@ -40,7 +40,6 @@ final _yellowBox = Container( | @@ -40,7 +40,6 @@ final _yellowBox = Container( | ||
40 | color: PdfColors.yellow, | 40 | color: PdfColors.yellow, |
41 | ); | 41 | ); |
42 | 42 | ||
43 | - | ||
44 | void main() { | 43 | void main() { |
45 | setUpAll(() { | 44 | setUpAll(() { |
46 | Document.debug = true; | 45 | Document.debug = true; |
@@ -227,10 +226,7 @@ void main() { | @@ -227,10 +226,7 @@ void main() { | ||
227 | pageFormat: const PdfPageFormat(150, 150), | 226 | pageFormat: const PdfPageFormat(150, 150), |
228 | build: (Context context) { | 227 | build: (Context context) { |
229 | return [ | 228 | return [ |
230 | - ListView(children: [ | ||
231 | - for(int i = 0; i < 30; i++) | ||
232 | - Text('Hello World') | ||
233 | - ]), | 229 | + ListView(children: [for (int i = 0; i < 30; i++) Text('Hello World')]), |
234 | ]; | 230 | ]; |
235 | }, | 231 | }, |
236 | ), | 232 | ), |
@@ -244,10 +240,7 @@ void main() { | @@ -244,10 +240,7 @@ void main() { | ||
244 | pageFormat: const PdfPageFormat(150, 150), | 240 | pageFormat: const PdfPageFormat(150, 150), |
245 | build: (Context context) { | 241 | build: (Context context) { |
246 | return [ | 242 | return [ |
247 | - ListView(children: [ | ||
248 | - for(int i = 0; i < 30; i++) | ||
249 | - Text('Hello World') | ||
250 | - ]), | 243 | + ListView(children: [for (int i = 0; i < 30; i++) Text('Hello World')]), |
251 | ]; | 244 | ]; |
252 | }, | 245 | }, |
253 | ), | 246 | ), |
@@ -291,7 +284,7 @@ void main() { | @@ -291,7 +284,7 @@ void main() { | ||
291 | pageFormat: const PdfPageFormat(150, 150), | 284 | pageFormat: const PdfPageFormat(150, 150), |
292 | build: (Context context) { | 285 | build: (Context context) { |
293 | return Align( | 286 | return Align( |
294 | - alignment: AlignmentDirectional.centerStart, | 287 | + alignment: AlignmentDirectional.centerStart, |
295 | child: _blueBox, | 288 | child: _blueBox, |
296 | ); | 289 | ); |
297 | }, | 290 | }, |
@@ -398,6 +391,93 @@ void main() { | @@ -398,6 +391,93 @@ void main() { | ||
398 | ); | 391 | ); |
399 | }); | 392 | }); |
400 | 393 | ||
394 | + test('Should render Grid with run alignment right', () { | ||
395 | + pdf.addPage( | ||
396 | + Page( | ||
397 | + textDirection: TextDirection.rtl, | ||
398 | + pageFormat: const PdfPageFormat(150, 150), | ||
399 | + build: (Context context) { | ||
400 | + return GridView( | ||
401 | + crossAxisCount: 3, | ||
402 | + childAspectRatio: 1, | ||
403 | + direction: Axis.vertical, | ||
404 | + children: [ | ||
405 | + for (int i = 0; i < 8; i++) | ||
406 | + Container( | ||
407 | + color: [PdfColors.blue, PdfColors.red, PdfColors.yellow][i % 3], | ||
408 | + ), | ||
409 | + ], | ||
410 | + ); | ||
411 | + }, | ||
412 | + ), | ||
413 | + ); | ||
414 | + }); | ||
415 | + | ||
416 | + test('Should render Grid with run alignment left', () { | ||
417 | + pdf.addPage( | ||
418 | + Page( | ||
419 | + textDirection: TextDirection.ltr, | ||
420 | + pageFormat: const PdfPageFormat(150, 150), | ||
421 | + build: (Context context) { | ||
422 | + return GridView( | ||
423 | + crossAxisCount: 3, | ||
424 | + childAspectRatio: 1, | ||
425 | + direction: Axis.vertical, | ||
426 | + children: [ | ||
427 | + for (int i = 0; i < 7; i++) | ||
428 | + Container( | ||
429 | + color: [PdfColors.blue, PdfColors.red, PdfColors.yellow][i % 3], | ||
430 | + ), | ||
431 | + ], | ||
432 | + ); | ||
433 | + }, | ||
434 | + ), | ||
435 | + ); | ||
436 | + }); | ||
437 | + test('Should render Grid (horizontal) with run alignment right', () { | ||
438 | + pdf.addPage( | ||
439 | + Page( | ||
440 | + textDirection: TextDirection.rtl, | ||
441 | + pageFormat: const PdfPageFormat(150, 150), | ||
442 | + build: (Context context) { | ||
443 | + return GridView( | ||
444 | + crossAxisCount: 3, | ||
445 | + childAspectRatio: 1, | ||
446 | + direction: Axis.horizontal, | ||
447 | + children: [ | ||
448 | + for (int i = 0; i < 7; i++) | ||
449 | + Container( | ||
450 | + color: [PdfColors.blue, PdfColors.red, PdfColors.yellow][i % 3], | ||
451 | + ), | ||
452 | + ], | ||
453 | + ); | ||
454 | + }, | ||
455 | + ), | ||
456 | + ); | ||
457 | + }); | ||
458 | + | ||
459 | + test('Should render Grid (horizontal) with run alignment left', () { | ||
460 | + pdf.addPage( | ||
461 | + Page( | ||
462 | + textDirection: TextDirection.ltr, | ||
463 | + pageFormat: const PdfPageFormat(150, 150), | ||
464 | + build: (Context context) { | ||
465 | + return GridView( | ||
466 | + crossAxisCount: 3, | ||
467 | + childAspectRatio: 1, | ||
468 | + direction: Axis.horizontal, | ||
469 | + children: [ | ||
470 | + for (int i = 0; i < 7; i++) | ||
471 | + Container( | ||
472 | + color: [PdfColors.blue, PdfColors.red, PdfColors.yellow][i % 3], | ||
473 | + ), | ||
474 | + ], | ||
475 | + ); | ||
476 | + }, | ||
477 | + ), | ||
478 | + ); | ||
479 | + }); | ||
480 | + | ||
401 | tearDownAll(() async { | 481 | tearDownAll(() async { |
402 | final file = File('rtl-layout.pdf'); | 482 | final file = File('rtl-layout.pdf'); |
403 | await file.writeAsBytes(await pdf.save()); | 483 | await file.writeAsBytes(await pdf.save()); |
-
Please register or login to post a comment