David PHAM-VAN

Improve Container tests

@@ -24,7 +24,7 @@ import 'package:pdf/widgets.dart'; @@ -24,7 +24,7 @@ import 'package:pdf/widgets.dart';
24 24
25 Document pdf; 25 Document pdf;
26 26
27 -Uint32List generateBitmap(int w, int h) { 27 +PdfImage generateBitmap(PdfDocument pdf, int w, int h) {
28 final Uint32List bm = Uint32List(w * h); 28 final Uint32List bm = Uint32List(w * h);
29 final double dw = w.toDouble(); 29 final double dw = w.toDouble();
30 final double dh = h.toDouble(); 30 final double dh = h.toDouble();
@@ -37,7 +37,12 @@ Uint32List generateBitmap(int w, int h) { @@ -37,7 +37,12 @@ Uint32List generateBitmap(int w, int h) {
37 } 37 }
38 } 38 }
39 39
40 - return bm; 40 + return PdfImage(
  41 + pdf,
  42 + image: bm.buffer.asUint8List(),
  43 + width: w,
  44 + height: h,
  45 + );
41 } 46 }
42 47
43 void main() { 48 void main() {
@@ -71,56 +76,43 @@ void main() { @@ -71,56 +76,43 @@ void main() {
71 }); 76 });
72 77
73 test('Container Widgets Image', () { 78 test('Container Widgets Image', () {
74 - final Uint32List img = generateBitmap(100, 100);  
75 - final PdfImage image = PdfImage(pdf.document,  
76 - image: img.buffer.asUint8List(), width: 100, height: 100); 79 + final PdfImage image = generateBitmap(pdf.document, 100, 200);
77 80
78 - pdf.addPage(Page(  
79 - build: (Context context) => Container(  
80 - alignment: Alignment.center,  
81 - margin: const EdgeInsets.all(30),  
82 - padding: const EdgeInsets.all(20),  
83 - decoration: BoxDecoration(  
84 - image: DecorationImage(image: image, fit: BoxFit.cover),  
85 - ),  
86 - width: 200,  
87 - height: 400,  
88 - // child: Placeholder(),  
89 - ),  
90 - ));  
91 - });  
92 -  
93 - test('Container Widgets BoxShape Image', () {  
94 - final Uint32List img = generateBitmap(100, 100);  
95 - final PdfImage image = PdfImage(pdf.document,  
96 - image: img.buffer.asUint8List(), width: 100, height: 100);  
97 -  
98 - pdf.addPage(Page(  
99 - build: (Context context) => Center(  
100 - child: Column(  
101 - mainAxisAlignment: MainAxisAlignment.spaceEvenly,  
102 - children: <Widget>[ 81 + final List<Widget> widgets = <Widget>[];
  82 + for (BoxShape shape in BoxShape.values) {
  83 + for (BoxFit fit in BoxFit.values) {
  84 + widgets.add(
103 Container( 85 Container(
104 - height: 200.0,  
105 - width: 200.0,  
106 - decoration: BoxDecoration(  
107 - shape: BoxShape.circle,  
108 - image: DecorationImage(image: image, fit: BoxFit.cover),  
109 - ),  
110 - ),  
111 - Container(  
112 - height: 200.0,  
113 - width: 200.0, 86 + alignment: Alignment.center,
114 decoration: BoxDecoration( 87 decoration: BoxDecoration(
115 - shape: BoxShape.rectangle,  
116 - borderRadius: 40,  
117 - image: DecorationImage(image: image, fit: BoxFit.cover), 88 + shape: shape,
  89 + borderRadius: 10,
  90 + image: DecorationImage(image: image, fit: fit),
118 ), 91 ),
  92 + width: 100,
  93 + height: 100,
  94 + child: Container(
  95 + width: 70,
  96 + color: PdfColors.yellow,
  97 + child: Text(
  98 + '$fit\n$shape',
  99 + textAlign: TextAlign.center,
  100 + textScaleFactor: 0.6,
119 ), 101 ),
120 - ],  
121 ), 102 ),
122 ), 103 ),
123 - )); 104 + );
  105 + }
  106 + }
  107 +
  108 + pdf.addPage(MultiPage(
  109 + build: (Context context) => <Widget>[
  110 + Wrap(
  111 + spacing: 10,
  112 + runSpacing: 10,
  113 + children: widgets,
  114 + )
  115 + ]));
124 }); 116 });
125 117
126 test('Container Widgets BoxShape Border', () { 118 test('Container Widgets BoxShape Border', () {