basic.dart
25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'dart:math' as math;
import 'package:meta/meta.dart';
import 'package:pdf/pdf.dart';
import 'package:vector_math/vector_math_64.dart';
import 'box_border.dart';
import 'container.dart';
import 'decoration.dart';
import 'geometry.dart';
import 'widget.dart';
enum BoxFit { fill, contain, cover, fitWidth, fitHeight, none, scaleDown }
class LimitedBox extends SingleChildWidget {
LimitedBox({
this.maxWidth = double.infinity,
this.maxHeight = double.infinity,
Widget child,
}) : assert(maxWidth != null && maxWidth >= 0.0),
assert(maxHeight != null && maxHeight >= 0.0),
super(child: child);
final double maxWidth;
final double maxHeight;
BoxConstraints _limitConstraints(BoxConstraints constraints) {
return BoxConstraints(
minWidth: constraints.minWidth,
maxWidth: constraints.hasBoundedWidth
? constraints.maxWidth
: constraints.constrainWidth(maxWidth),
minHeight: constraints.minHeight,
maxHeight: constraints.hasBoundedHeight
? constraints.maxHeight
: constraints.constrainHeight(maxHeight));
}
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
PdfPoint size;
if (child != null) {
child.layout(context, _limitConstraints(constraints),
parentUsesSize: true);
assert(child.box != null);
size = constraints.constrain(child.box.size);
} else {
size = _limitConstraints(constraints).constrain(PdfPoint.zero);
}
box = PdfRect.fromPoints(PdfPoint.zero, size);
}
@override
void paint(Context context) {
super.paint(context);
paintChild(context);
}
}
class Padding extends SingleChildWidget {
Padding({
@required this.padding,
Widget child,
}) : assert(padding != null),
super(child: child);
final EdgeInsets padding;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
if (child != null) {
final childConstraints = constraints.deflate(padding);
child.layout(context, childConstraints, parentUsesSize: parentUsesSize);
assert(child.box != null);
box = constraints.constrainRect(
width: child.box.width + padding.horizontal,
height: child.box.height + padding.vertical);
} else {
box = constraints.constrainRect(
width: padding.horizontal, height: padding.vertical);
}
}
@override
void debugPaint(Context context) {
context.canvas
..setFillColor(PdfColors.lime)
..moveTo(box.x, box.y)
..lineTo(box.right, box.y)
..lineTo(box.right, box.top)
..lineTo(box.x, box.top)
..moveTo(box.x + padding.left, box.y + padding.bottom)
..lineTo(box.x + padding.left, box.top - padding.top)
..lineTo(box.right - padding.right, box.top - padding.top)
..lineTo(box.right - padding.right, box.y + padding.bottom)
..fillPath();
}
@override
void paint(Context context) {
super.paint(context);
if (child != null) {
final mat = Matrix4.identity();
mat.translate(box.x + padding.left, box.y + padding.bottom);
context.canvas
..saveContext()
..setTransform(mat);
child.paint(context);
context.canvas.restoreContext();
}
}
}
class Transform extends SingleChildWidget {
Transform({
@required this.transform,
this.origin,
this.alignment,
this.adjustLayout = false,
Widget child,
}) : assert(transform != null),
super(child: child);
/// Creates a widget that transforms its child using a rotation around the
/// center.
Transform.rotate({
@required double angle,
this.origin,
this.alignment = Alignment.center,
Widget child,
}) : transform = Matrix4.rotationZ(angle),
adjustLayout = false,
super(child: child);
/// Creates a widget that transforms its child using a rotation around the
/// center and relayout the bounding box.
Transform.rotateBox({
@required double angle,
Widget child,
}) : transform = Matrix4.rotationZ(angle),
adjustLayout = true,
alignment = null,
origin = null,
super(child: child);
/// Creates a widget that transforms its child using a translation.
Transform.translate({
@required PdfPoint offset,
Widget child,
}) : transform = Matrix4.translationValues(offset.x, offset.y, 0),
origin = null,
alignment = null,
adjustLayout = false,
super(child: child);
/// Creates a widget that scales its child uniformly.
Transform.scale({
@required double scale,
this.origin,
this.alignment = Alignment.center,
Widget child,
}) : transform = Matrix4.diagonal3Values(scale, scale, 1),
adjustLayout = false,
super(child: child);
/// The matrix to transform the child by during painting.
final Matrix4 transform;
/// The origin of the coordinate system
final PdfPoint origin;
/// The alignment of the origin, relative to the size of the box.
final Alignment alignment;
final bool adjustLayout;
Matrix4 get _effectiveTransform {
final result = Matrix4.identity();
if (origin != null) {
result.translate(origin.x, origin.y);
}
result.translate(box.x, box.y);
PdfPoint translation;
if (alignment != null) {
translation = alignment.alongSize(box.size);
result.translate(translation.x, translation.y);
}
result.multiply(transform);
if (alignment != null) {
result.translate(-translation.x, -translation.y);
}
if (origin != null) {
result.translate(-origin.x, -origin.y);
}
return result;
}
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
if (!adjustLayout) {
return super.layout(context, constraints, parentUsesSize: parentUsesSize);
}
if (child != null) {
child.layout(context, constraints, parentUsesSize: parentUsesSize);
assert(child.box != null);
final mat = transform;
final values = mat.applyToVector3Array(<double>[
child.box.left,
child.box.top,
0,
child.box.right,
child.box.top,
0,
child.box.right,
child.box.bottom,
0,
child.box.left,
child.box.bottom,
0,
]);
final dx = -math.min(
math.min(math.min(values[0], values[3]), values[6]), values[9]);
final dy = -math.min(
math.min(math.min(values[1], values[4]), values[7]), values[10]);
box = PdfRect.fromLTRB(
0,
0,
math.max(math.max(math.max(values[0], values[3]), values[6]),
values[9]) +
dx,
math.max(math.max(math.max(values[1], values[4]), values[7]),
values[10]) +
dy,
);
transform.leftTranslate(dx, dy);
} else {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.smallest);
}
}
@override
void paint(Context context) {
super.paint(context);
if (child != null) {
final mat = _effectiveTransform;
context.canvas
..saveContext()
..setTransform(mat);
child.paint(context);
context.canvas.restoreContext();
}
}
}
/// A widget that aligns its child within itself and optionally sizes itself
/// based on the child's size.
class Align extends SingleChildWidget {
Align(
{this.alignment = Alignment.center,
this.widthFactor,
this.heightFactor,
Widget child})
: assert(alignment != null),
assert(widthFactor == null || widthFactor >= 0.0),
assert(heightFactor == null || heightFactor >= 0.0),
super(child: child);
/// How to align the child.
final Alignment alignment;
/// If non-null, sets its width to the child's width multiplied by this factor.
final double widthFactor;
/// If non-null, sets its height to the child's height multiplied by this factor.
final double heightFactor;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
final shrinkWrapWidth =
widthFactor != null || constraints.maxWidth == double.infinity;
final shrinkWrapHeight =
heightFactor != null || constraints.maxHeight == double.infinity;
if (child != null) {
child.layout(context, constraints.loosen(), parentUsesSize: true);
assert(child.box != null);
box = constraints.constrainRect(
width: shrinkWrapWidth
? child.box.width * (widthFactor ?? 1.0)
: double.infinity,
height: shrinkWrapHeight
? child.box.height * (heightFactor ?? 1.0)
: double.infinity);
child.box = alignment.inscribe(child.box.size, box);
} else {
box = constraints.constrainRect(
width: shrinkWrapWidth ? 0.0 : double.infinity,
height: shrinkWrapHeight ? 0.0 : double.infinity);
}
}
@override
void debugPaint(Context context) {
context.canvas
..setStrokeColor(PdfColors.green)
..setLineWidth(1)
..drawBox(box);
if (child == null) {
context.canvas.strokePath();
return;
}
if (child.box.bottom > 0) {
final headSize = math.min((child.box.bottom) * 0.2, 10);
context.canvas
..moveTo(
box.left + child.box.horizondalCenter,
box.bottom,
)
..lineTo(box.left + child.box.horizondalCenter,
box.bottom + child.box.bottom)
..lineTo(box.left + child.box.horizondalCenter - headSize,
box.bottom + child.box.bottom - headSize)
..moveTo(box.left + child.box.horizondalCenter,
box.bottom + child.box.bottom)
..lineTo(box.left + child.box.horizondalCenter + headSize,
box.bottom + child.box.bottom - headSize);
}
if (box.bottom + child.box.top < box.top) {
final headSize =
math.min((box.top - child.box.top - box.bottom) * 0.2, 10);
context.canvas
..moveTo(box.left + child.box.horizondalCenter, box.top)
..lineTo(
box.left + child.box.horizondalCenter, box.bottom + child.box.top)
..lineTo(box.left + child.box.horizondalCenter - headSize,
box.bottom + child.box.top + headSize)
..moveTo(
box.left + child.box.horizondalCenter, box.bottom + child.box.top)
..lineTo(box.left + child.box.horizondalCenter + headSize,
box.bottom + child.box.top + headSize);
}
if (child.box.left > 0) {
final headSize = math.min((child.box.left) * 0.2, 10);
context.canvas
..moveTo(box.left, box.bottom + child.box.verticalCenter)
..lineTo(
box.left + child.box.left, box.bottom + child.box.verticalCenter)
..lineTo(box.left + child.box.left - headSize,
box.bottom + child.box.verticalCenter - headSize)
..moveTo(
box.left + child.box.left, box.bottom + child.box.verticalCenter)
..lineTo(box.left + child.box.left - headSize,
box.bottom + child.box.verticalCenter + headSize);
}
if (box.left + child.box.right < box.right) {
final headSize =
math.min((box.right - child.box.right - box.left) * 0.2, 10);
context.canvas
..moveTo(box.right, box.bottom + child.box.verticalCenter)
..lineTo(
box.left + child.box.right, box.bottom + child.box.verticalCenter)
..lineTo(box.left + child.box.right + headSize,
box.bottom + child.box.verticalCenter - headSize)
..moveTo(
box.left + child.box.right, box.bottom + child.box.verticalCenter)
..lineTo(box.left + child.box.right + headSize,
box.bottom + child.box.verticalCenter + headSize);
}
context.canvas.strokePath();
}
@override
void paint(Context context) {
super.paint(context);
paintChild(context);
}
}
/// A widget that imposes additional constraints on its child.
class ConstrainedBox extends SingleChildWidget {
ConstrainedBox({@required this.constraints, Widget child})
: assert(constraints != null),
super(child: child);
/// The additional constraints to impose on the child.
final BoxConstraints constraints;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
if (child != null) {
child.layout(context, this.constraints.enforce(constraints),
parentUsesSize: true);
assert(child.box != null);
box = child.box;
} else {
box = PdfRect.fromPoints(PdfPoint.zero,
this.constraints.enforce(constraints).constrain(PdfPoint.zero));
}
}
@override
void paint(Context context) {
super.paint(context);
paintChild(context);
}
}
class Center extends Align {
Center({double widthFactor, double heightFactor, Widget child})
: super(
widthFactor: widthFactor, heightFactor: heightFactor, child: child);
}
/// Scales and positions its child within itself according to [fit].
class FittedBox extends SingleChildWidget {
FittedBox({
this.fit = BoxFit.contain,
this.alignment = Alignment.center,
Widget child,
}) : assert(fit != null),
assert(alignment != null),
super(child: child);
/// How to inscribe the child into the space allocated during layout.
final BoxFit fit;
/// How to align the child within its parent's bounds.
final Alignment alignment;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
PdfPoint size;
if (child != null) {
child.layout(context, const BoxConstraints(), parentUsesSize: true);
assert(child.box != null);
size = constraints
.constrainSizeAndAttemptToPreserveAspectRatio(child.box.size);
} else {
size = constraints.smallest;
}
box = PdfRect.fromPoints(PdfPoint.zero, size);
}
@override
void paint(Context context) {
super.paint(context);
if (child != null) {
final childSize = child.box.size;
final sizes = applyBoxFit(fit, childSize, box.size);
final scaleX = sizes.destination.x / sizes.source.x;
final scaleY = sizes.destination.y / sizes.source.y;
final sourceRect = alignment.inscribe(
sizes.source, PdfRect.fromPoints(PdfPoint.zero, childSize));
final destinationRect = alignment.inscribe(sizes.destination, box);
final mat =
Matrix4.translationValues(destinationRect.x, destinationRect.y, 0)
..scale(scaleX, scaleY, 1)
..translate(-sourceRect.x, -sourceRect.y);
context.canvas
..saveContext()
..drawBox(box)
..clipPath()
..setTransform(mat);
child.paint(context);
context.canvas.restoreContext();
}
}
}
class AspectRatio extends SingleChildWidget {
AspectRatio({@required this.aspectRatio, Widget child})
: assert(aspectRatio != null),
super(child: child);
/// The aspect ratio to attempt to use.
final double aspectRatio;
PdfPoint _applyAspectRatio(BoxConstraints constraints) {
if (constraints.isTight) {
return constraints.smallest;
}
var width = constraints.maxWidth;
double height;
if (width.isFinite) {
height = width / aspectRatio;
} else {
height = constraints.maxHeight;
width = height * aspectRatio;
}
if (width > constraints.maxWidth) {
width = constraints.maxWidth;
height = width / aspectRatio;
}
if (height > constraints.maxHeight) {
height = constraints.maxHeight;
width = height * aspectRatio;
}
if (width < constraints.minWidth) {
width = constraints.minWidth;
height = width / aspectRatio;
}
if (height < constraints.minHeight) {
height = constraints.minHeight;
width = height * aspectRatio;
}
return constraints.constrain(PdfPoint(width, height));
}
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
box = PdfRect.fromPoints(PdfPoint.zero, _applyAspectRatio(constraints));
if (child != null) {
child.layout(context,
BoxConstraints.tightFor(width: box.width, height: box.height));
}
assert(child.box != null);
}
@override
void paint(Context context) {
super.paint(context);
paintChild(context);
}
}
typedef CustomPainter = Function(PdfGraphics canvas, PdfPoint size);
class CustomPaint extends SingleChildWidget {
CustomPaint({
this.painter,
this.foregroundPainter,
this.size = PdfPoint.zero,
Widget child,
}) : super(child: child);
final CustomPainter painter;
final CustomPainter foregroundPainter;
final PdfPoint size;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
if (child != null) {
child.layout(context, constraints, parentUsesSize: parentUsesSize);
assert(child.box != null);
box = child.box;
} else {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.constrain(size));
}
}
@override
void paint(Context context) {
super.paint(context);
final mat = Matrix4.identity();
mat.translate(box.x, box.y);
context.canvas
..saveContext()
..setTransform(mat);
if (painter != null) {
painter(context.canvas, box.size);
}
if (child != null) {
child.paint(context);
}
if (foregroundPainter != null) {
foregroundPainter(context.canvas, box.size);
}
context.canvas.restoreContext();
}
}
/// A box with a specified size.
class SizedBox extends StatelessWidget {
/// Creates a fixed size box.
SizedBox({this.width, this.height, this.child});
/// Creates a box that will become as large as its parent allows.
SizedBox.expand({this.child})
: width = double.infinity,
height = double.infinity;
/// Creates a box that will become as small as its parent allows.
SizedBox.shrink({this.child})
: width = 0.0,
height = 0.0;
/// Creates a box with the specified size.
SizedBox.fromSize({this.child, PdfPoint size})
: width = size?.x,
height = size?.y;
/// If non-null, requires the child to have exactly this width.
final double width;
/// If non-null, requires the child to have exactly this height.
final double height;
final Widget child;
@override
Widget build(Context context) {
return ConstrainedBox(
child: child,
constraints: BoxConstraints.tightFor(width: width, height: height));
}
}
typedef WidgetBuilder = Widget Function(Context context);
/// A platonic widget that calls a closure to obtain its child widget.
class Builder extends StatelessWidget {
/// Creates a widget that delegates its build to a callback.
///
/// The [builder] argument must not be null.
Builder({
@required this.builder,
}) : assert(builder != null),
super();
/// Called to obtain the child widget.
final WidgetBuilder builder;
@override
Widget build(Context context) => builder(context);
}
/// The signature of the [LayoutBuilder] builder function.
typedef LayoutWidgetBuilder = Widget Function(
Context context, BoxConstraints constraints);
/// Builds a widget tree that can depend on the parent widget's size.
class LayoutBuilder extends StatelessWidget {
/// Creates a widget that defers its building until layout.
LayoutBuilder({
@required this.builder,
}) : assert(builder != null);
/// Called at layout time to construct the widget tree.
final LayoutWidgetBuilder builder;
BoxConstraints _constraints;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
_constraints = constraints;
super.layout(context, constraints);
}
@override
Widget build(Context context) => builder(context, _constraints);
}
class FullPage extends SingleChildWidget {
FullPage({
@required this.ignoreMargins,
Widget child,
}) : assert(ignoreMargins != null),
super(child: child);
final bool ignoreMargins;
BoxConstraints _getConstraints(Context context) {
assert(context.page.pageFormat.width != double.infinity);
assert(context.page.pageFormat.height != double.infinity);
return ignoreMargins
? BoxConstraints.tightFor(
width: context.page.pageFormat.width,
height: context.page.pageFormat.height,
)
: BoxConstraints.tightFor(
width: context.page.pageFormat.availableWidth,
height: context.page.pageFormat.availableHeight,
);
}
PdfRect _getBox(Context context) {
final box = _getConstraints(context).constrainRect();
if (ignoreMargins) {
return box;
}
return PdfRect.fromPoints(
PdfPoint(
context.page.pageFormat.marginLeft,
context.page.pageFormat.marginTop,
),
box.size);
}
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
final constraints = _getConstraints(context);
if (child != null) {
child.layout(context, constraints, parentUsesSize: false);
assert(child.box != null);
}
box = _getBox(context);
}
@override
void debugPaint(Context context) {}
@override
void paint(Context context) {
super.paint(context);
if (child == null) {
return;
}
final box = _getBox(context);
final mat = Matrix4.tryInvert(context.canvas.getTransform());
mat.translate(box.x, box.y);
context.canvas
..saveContext()
..setTransform(mat);
child.paint(context);
context.canvas.restoreContext();
}
}
class Opacity extends SingleChildWidget {
Opacity({
@required this.opacity,
Widget child,
}) : assert(opacity != null),
super(child: child);
final double opacity;
@override
void paint(Context context) {
super.paint(context);
if (child != null) {
final mat = Matrix4.identity();
mat.translate(box.x, box.y);
context.canvas
..saveContext()
..setTransform(mat)
..setGraphicState(PdfGraphicState(opacity: opacity));
child.paint(context);
context.canvas.restoreContext();
}
}
}
class Divider extends StatelessWidget {
Divider({
this.height,
this.thickness,
this.indent,
this.endIndent,
this.color,
}) : assert(height == null || height >= 0.0),
assert(thickness == null || thickness >= 0.0),
assert(indent == null || indent >= 0.0),
assert(endIndent == null || endIndent >= 0.0);
/// The color to use when painting the line.
final PdfColor color;
/// The amount of empty space to the trailing edge of the divider.
final double endIndent;
/// The divider's height extent.
final double height;
/// The amount of empty space to the leading edge of the divider.
final double indent;
/// The thickness of the line drawn within the divider.
final double thickness;
@override
Widget build(Context context) {
final height = this.height ?? 16;
final thickness = this.thickness ?? 1;
final indent = this.indent ?? 0;
final endIndent = this.endIndent ?? 0;
final color = this.color ?? PdfColors.black;
return SizedBox(
height: height,
child: Center(
child: Container(
height: thickness,
margin: EdgeInsets.only(left: indent, right: endIndent),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: color,
width: thickness,
),
),
),
),
),
);
}
}
class VerticalDivider extends StatelessWidget {
VerticalDivider({
this.width,
this.thickness,
this.indent,
this.endIndent,
this.color,
}) : assert(width == null || width >= 0.0),
assert(thickness == null || thickness >= 0.0),
assert(indent == null || indent >= 0.0),
assert(endIndent == null || endIndent >= 0.0);
/// The color to use when painting the line.
final PdfColor color;
/// The amount of empty space to the trailing edge of the divider.
final double endIndent;
/// The divider's width extent.
final double width;
/// The amount of empty space to the leading edge of the divider.
final double indent;
/// The thickness of the line drawn within the divider.
final double thickness;
@override
Widget build(Context context) {
final width = this.width ?? 16;
final thickness = this.thickness ?? 1;
final indent = this.indent ?? 0;
final endIndent = this.endIndent ?? 0;
final color = this.color ?? PdfColors.black;
return SizedBox(
width: width,
child: Center(
child: Container(
width: thickness,
margin: EdgeInsets.only(top: indent, bottom: endIndent),
decoration: BoxDecoration(
border: Border(
left: BorderSide(
color: color,
width: thickness,
),
),
),
),
),
);
}
}