@@ -7,7 +7,8 @@ import 'package:camera_android_camerax/src/camerax_library.dart';
7
7
import 'package:camera_android_camerax/src/camerax_proxy.dart' ;
8
8
import 'package:camera_platform_interface/camera_platform_interface.dart' ;
9
9
import 'package:flutter/services.dart' ;
10
- import 'package:flutter/widgets.dart' show RotatedBox, Texture;
10
+ import 'package:flutter/widgets.dart'
11
+ show MatrixUtils, RotatedBox, Texture, Transform;
11
12
import 'package:flutter_test/flutter_test.dart' ;
12
13
import 'package:mockito/mockito.dart' ;
13
14
@@ -380,6 +381,70 @@ void main() {
380
381
) =>
381
382
'Expected the preview to be rotated by $expectedQuarterTurns quarter turns (which is ${expectedQuarterTurns * 90 } degrees clockwise) but instead was rotated $actualQuarterTurns quarter turns.' ;
382
383
384
+ /// Checks that the transform matrix (Matrix4) mirrors across the x-axis by
385
+ /// confirming the following to be the transformation matrix:
386
+ /// [[-1.0, 0.0, 0.0, 0.0] ,
387
+ /// [ 0.0, 1.0, 0.0, 0.0] ,
388
+ /// [ 0.0, 0.0, 1.0, 0.0] ,
389
+ /// [ 0.0, 0.0, 0.0, 1.0] ]
390
+ void checkXAxisIsMirrored (Matrix4 transformationMatrix) {
391
+ final Matrix4 mirrorAcrossXMatrix = Matrix4 (
392
+ - 1.0 ,
393
+ 0.0 ,
394
+ 0.0 ,
395
+ 0.0 ,
396
+ 0.0 ,
397
+ 1.0 ,
398
+ 0.0 ,
399
+ 0.0 ,
400
+ 0.0 ,
401
+ 0.0 ,
402
+ 1.0 ,
403
+ 0.0 ,
404
+ 0.0 ,
405
+ 0.0 ,
406
+ 0.0 ,
407
+ 1.0 ,
408
+ );
409
+
410
+ expect (
411
+ MatrixUtils .matrixEquals (mirrorAcrossXMatrix, transformationMatrix),
412
+ isTrue,
413
+ );
414
+ }
415
+
416
+ /// Checks that the transform matrix (Matrix4) mirrors across the y-axis by
417
+ /// confirming the following to be the transformation matrix:
418
+ /// [[1.0, 0.0, 0.0, 0.0] ,
419
+ /// [ 0.0, -1.0, 0.0, 0.0] ,
420
+ /// [ 0.0, 0.0, 1.0, 0.0] ,
421
+ /// [ 0.0, 0.0, 0.0, 1.0] ]
422
+ void checkYAxisIsMirrored (Matrix4 transformationMatrix) {
423
+ final Matrix4 mirrorAcrossYMatrix = Matrix4 (
424
+ 1.0 ,
425
+ 0.0 ,
426
+ 0.0 ,
427
+ 0.0 ,
428
+ 0.0 ,
429
+ - 1.0 ,
430
+ 0.0 ,
431
+ 0.0 ,
432
+ 0.0 ,
433
+ 0.0 ,
434
+ 1.0 ,
435
+ 0.0 ,
436
+ 0.0 ,
437
+ 0.0 ,
438
+ 0.0 ,
439
+ 1.0 ,
440
+ );
441
+
442
+ expect (
443
+ MatrixUtils .matrixEquals (mirrorAcrossYMatrix, transformationMatrix),
444
+ isTrue,
445
+ );
446
+ }
447
+
383
448
group ('when handlesCropAndRotation is true' , () {
384
449
// Test that preview rotation responds to initial default display rotation:
385
450
group ('initial device orientation is landscapeRight,' , () {
@@ -1167,8 +1232,19 @@ void main() {
1167
1232
find.byType (RotatedBox ),
1168
1233
);
1169
1234
1170
- expect (rotatedBox.child, isA <Texture >());
1171
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1235
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1236
+ // preview to mirror the preview, since the front camera is being
1237
+ // used.
1238
+ expect (rotatedBox.child, isA <Transform >());
1239
+
1240
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1241
+ final Matrix4 transformedPreviewMatrix =
1242
+ transformedPreview.transform;
1243
+
1244
+ // Since the front camera is in portrait mode, we expect the camera
1245
+ // preview to be mirrored across the y-axis.
1246
+ checkYAxisIsMirrored (transformedPreviewMatrix);
1247
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1172
1248
expect (
1173
1249
rotatedBox.quarterTurns,
1174
1250
expectedQuarterTurns,
@@ -1216,8 +1292,20 @@ void main() {
1216
1292
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
1217
1293
find.byType (RotatedBox ),
1218
1294
);
1219
- expect (rotatedBox.child, isA <Texture >());
1220
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1295
+
1296
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1297
+ // preview to mirror the preview, since the front camera is being
1298
+ // used.
1299
+ expect (rotatedBox.child, isA <Transform >());
1300
+
1301
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1302
+ final Matrix4 transformedPreviewMatrix =
1303
+ transformedPreview.transform;
1304
+
1305
+ // Since the front camera is in landscape mode, we expect the camera
1306
+ // preview to be mirrored across the x-axis.
1307
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1308
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1221
1309
expect (
1222
1310
rotatedBox.quarterTurns,
1223
1311
expectedQuarterTurns,
@@ -1265,8 +1353,20 @@ void main() {
1265
1353
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
1266
1354
find.byType (RotatedBox ),
1267
1355
);
1268
- expect (rotatedBox.child, isA <Texture >());
1269
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1356
+
1357
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1358
+ // preview to mirror the preview, since the front camera is being
1359
+ // used.
1360
+ expect (rotatedBox.child, isA <Transform >());
1361
+
1362
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1363
+ final Matrix4 transformedPreviewMatrix =
1364
+ transformedPreview.transform;
1365
+
1366
+ // Since the front camera is in portrait mode, we expect the camera
1367
+ // preview to be mirrored across the y-axis.
1368
+ checkYAxisIsMirrored (transformedPreviewMatrix);
1369
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1270
1370
expect (
1271
1371
rotatedBox.quarterTurns,
1272
1372
expectedQuarterTurns,
@@ -1314,8 +1414,20 @@ void main() {
1314
1414
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
1315
1415
find.byType (RotatedBox ),
1316
1416
);
1317
- expect (rotatedBox.child, isA <Texture >());
1318
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1417
+
1418
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1419
+ // preview to mirror the preview, since the front camera is being
1420
+ // used.
1421
+ expect (rotatedBox.child, isA <Transform >());
1422
+
1423
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1424
+ final Matrix4 transformedPreviewMatrix =
1425
+ transformedPreview.transform;
1426
+
1427
+ // Since the front camera is in landscape mode, we expect the camera
1428
+ // preview to be mirrored across the x-axis.
1429
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1430
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1319
1431
expect (
1320
1432
rotatedBox.quarterTurns,
1321
1433
expectedQuarterTurns,
@@ -1406,8 +1518,19 @@ void main() {
1406
1518
find.byType (RotatedBox ),
1407
1519
);
1408
1520
1409
- expect (rotatedBox.child, isA <Texture >());
1410
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1521
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1522
+ // preview to mirror the preview, since the front camera is being
1523
+ // used.
1524
+ expect (rotatedBox.child, isA <Transform >());
1525
+
1526
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1527
+ final Matrix4 transformedPreviewMatrix =
1528
+ transformedPreview.transform;
1529
+
1530
+ // Since the front camera is in landscape mode, we expect the camera
1531
+ // preview to be mirrored across the x-axis.
1532
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1533
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1411
1534
expect (
1412
1535
rotatedBox.quarterTurns,
1413
1536
expectedQuarterTurns,
@@ -1455,9 +1578,22 @@ void main() {
1455
1578
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
1456
1579
find.byType (RotatedBox ),
1457
1580
);
1581
+
1582
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1583
+ // preview to mirror the preview, since the front camera is being
1584
+ // used.
1585
+ expect (rotatedBox.child, isA <Transform >());
1586
+
1587
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1588
+ final Matrix4 transformedPreviewMatrix =
1589
+ transformedPreview.transform;
1590
+
1591
+ // Since the front camera is in landscape mode, we expect the camera
1592
+ // preview to be mirrored across the x-axis.
1593
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1594
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1595
+
1458
1596
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4 ;
1459
- expect (rotatedBox.child, isA <Texture >());
1460
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1461
1597
expect (
1462
1598
clockwiseQuarterTurns,
1463
1599
expectedQuarterTurns,
@@ -1503,9 +1639,22 @@ void main() {
1503
1639
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
1504
1640
find.byType (RotatedBox ),
1505
1641
);
1642
+
1643
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1644
+ // preview to mirror the preview, since the front camera is being
1645
+ // used.
1646
+ expect (rotatedBox.child, isA <Transform >());
1647
+
1648
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1649
+ final Matrix4 transformedPreviewMatrix =
1650
+ transformedPreview.transform;
1651
+
1652
+ // Since the front camera is in landscape mode, we expect the camera
1653
+ // preview to be mirrored across the x-axis.
1654
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1655
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1656
+
1506
1657
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4 ;
1507
- expect (rotatedBox.child, isA <Texture >());
1508
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1509
1658
expect (
1510
1659
clockwiseQuarterTurns,
1511
1660
expectedQuarterTurns,
@@ -1553,9 +1702,22 @@ void main() {
1553
1702
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
1554
1703
find.byType (RotatedBox ),
1555
1704
);
1705
+
1706
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1707
+ // preview to mirror the preview, since the front camera is being
1708
+ // used.
1709
+ expect (rotatedBox.child, isA <Transform >());
1710
+
1711
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1712
+ final Matrix4 transformedPreviewMatrix =
1713
+ transformedPreview.transform;
1714
+
1715
+ // Since the front camera is in landscape mode, we expect the camera
1716
+ // preview to be mirrored across the x-axis.
1717
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1718
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1719
+
1556
1720
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4 ;
1557
- expect (rotatedBox.child, isA <Texture >());
1558
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1559
1721
expect (
1560
1722
clockwiseQuarterTurns,
1561
1723
expectedQuarterTurns,
@@ -1662,12 +1824,24 @@ void main() {
1662
1824
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
1663
1825
find.byType (RotatedBox ),
1664
1826
);
1827
+
1828
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1829
+ // preview to mirror the preview, since the front camera is being
1830
+ // used.
1831
+ expect (rotatedBox.child, isA <Transform >());
1832
+
1833
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1834
+ final Matrix4 transformedPreviewMatrix = transformedPreview.transform;
1835
+
1836
+ // Since the front camera is in landscape mode, we expect the camera
1837
+ // preview to be mirrored across the x-axis.
1838
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1839
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1840
+
1665
1841
final int clockwiseQuarterTurns =
1666
1842
rotatedBox.quarterTurns < 0
1667
1843
? rotatedBox.quarterTurns + 4
1668
1844
: rotatedBox.quarterTurns;
1669
- expect (rotatedBox.child, isA <Texture >());
1670
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1671
1845
expect (
1672
1846
clockwiseQuarterTurns,
1673
1847
expectedQuarterTurns,
@@ -1760,12 +1934,30 @@ void main() {
1760
1934
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
1761
1935
find.byType (RotatedBox ),
1762
1936
);
1937
+
1938
+ // We expect a Transform widget to wrap the RotatedBox with the camera
1939
+ // preview to mirror the preview, since the front camera is being
1940
+ // used.
1941
+ expect (rotatedBox.child, isA <Transform >());
1942
+
1943
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
1944
+ final Matrix4 transformedPreviewMatrix = transformedPreview.transform;
1945
+
1946
+ // When the front camera is in landscape mode, we expect the camera
1947
+ // preview to be mirrored across the x-axis. When the front camera
1948
+ // is in portrait mode, we expect the camera preview to be mirrored
1949
+ // across the y-axis.
1950
+ if (currentDeviceOrientation == DeviceOrientation .landscapeLeft ||
1951
+ currentDeviceOrientation == DeviceOrientation .landscapeRight) {
1952
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1953
+ } else {
1954
+ checkYAxisIsMirrored (transformedPreviewMatrix);
1955
+ }
1956
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1763
1957
final int clockwiseQuarterTurns =
1764
1958
rotatedBox.quarterTurns < 0
1765
1959
? rotatedBox.quarterTurns + 4
1766
1960
: rotatedBox.quarterTurns;
1767
- expect (rotatedBox.child, isA <Texture >());
1768
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
1769
1961
expect (
1770
1962
clockwiseQuarterTurns,
1771
1963
expectedQuarterTurns,
@@ -2013,8 +2205,20 @@ void main() {
2013
2205
final RotatedBox rotatedBox = tester.widget <RotatedBox >(
2014
2206
find.byType (RotatedBox ),
2015
2207
);
2016
- expect (rotatedBox.child, isA <Texture >());
2017
- expect ((rotatedBox.child! as Texture ).textureId, cameraId);
2208
+
2209
+ // We expect a Transform widget to wrap the RotatedBox with the camera
2210
+ // preview to mirror the preview, since the front camera is being
2211
+ // used.
2212
+ expect (rotatedBox.child, isA <Transform >());
2213
+
2214
+ final Transform transformedPreview = rotatedBox.child! as Transform ;
2215
+ final Matrix4 transformedPreviewMatrix =
2216
+ transformedPreview.transform;
2217
+
2218
+ // Since the front camera is in landscape mode, we expect the camera
2219
+ // preview to be mirrored across the x-axis.
2220
+ checkXAxisIsMirrored (transformedPreviewMatrix);
2221
+ expect ((transformedPreview.child! as Texture ).textureId, cameraId);
2018
2222
expect (
2019
2223
rotatedBox.quarterTurns,
2020
2224
expectedQuarterTurns,
0 commit comments