Milad akarie
Committed by David PHAM-VAN

Add RTL support to Wrap widget

... ... @@ -16,6 +16,7 @@
import 'dart:math' as math;
import 'package:pdf/widgets.dart';
import 'package:vector_math/vector_math_64.dart';
import '../../pdf.dart';
... ... @@ -164,11 +165,14 @@ class Wrap extends MultiChildWidget with SpanningWidget {
double? mainAxisLimit = 0.0;
var flipMainAxis = false;
var flipCrossAxis = false;
final textDirection = Directionality.of(context);
switch (direction) {
case Axis.horizontal:
childConstraints = BoxConstraints(maxWidth: constraints.maxWidth);
mainAxisLimit = constraints.maxWidth;
if (textDirection == TextDirection.rtl) {
flipMainAxis = true;
}
if (verticalDirection == VerticalDirection.down) {
flipCrossAxis = true;
}
... ... @@ -179,6 +183,9 @@ class Wrap extends MultiChildWidget with SpanningWidget {
if (verticalDirection == VerticalDirection.down) {
flipMainAxis = true;
}
if (textDirection == TextDirection.rtl) {
flipCrossAxis = true;
}
break;
}
... ...
... ... @@ -34,6 +34,17 @@ final _redBox = Container(
color: PdfColors.red,
);
final _yellowBox = Container(
width: 50,
height: 50,
color: PdfColors.yellow,
);
final _greenBox = Container(
width: 50,
height: 50,
color: PdfColors.green,
);
void main() {
setUpAll(() {
Document.debug = true;
... ... @@ -124,6 +135,75 @@ void main() {
);
});
test('Wrap Should render blue,red,yellow ordered RTL', () {
pdf.addPage(
Page(
textDirection: TextDirection.rtl,
pageFormat: const PdfPageFormat(150, 150),
build: (Context context) => SizedBox(
width: 150,
height: 150,
child: Wrap(
children: [_blueBox, _redBox,_yellowBox],
)
),
),
);
});
test('Wrap Should render blue,red,yellow ordered LTR', () {
pdf.addPage(
Page(
textDirection: TextDirection.ltr,
pageFormat: const PdfPageFormat(150, 150),
build: (Context context) => SizedBox(
width: 150,
height: 150,
child: Wrap(
children: [_blueBox, _redBox,_yellowBox],
)
),
),
);
});
test('Wrap Should render blue,red,yellow ordered RTL aligned center', () {
pdf.addPage(
Page(
textDirection: TextDirection.rtl,
pageFormat: const PdfPageFormat(150, 150),
build: (Context context) => SizedBox(
width: 150,
height: 150,
child: Wrap(
spacing: 10,
runSpacing: 10,
runAlignment: WrapAlignment.center,
children: [_blueBox, _redBox,_yellowBox],
)
),
),
);
});
test('Wrap Should render blue,red,yellow ordered RTL aligned bottom', () {
pdf.addPage(
Page(
textDirection: TextDirection.rtl,
pageFormat: const PdfPageFormat(150, 150),
build: (Context context) => SizedBox(
width: 150,
height: 150,
child: Wrap(
spacing: 10,
runSpacing: 10,
runAlignment: WrapAlignment.end,
children: [_blueBox, _redBox,_yellowBox],
)
),
),
);
});
tearDownAll(() async {
final file = File('rtl-layout.pdf');
await file.writeAsBytes(await pdf.save());
... ...