Showing
1 changed file
with
28 additions
and
4 deletions
| @@ -64,12 +64,34 @@ class MobileScanner extends StatefulWidget { | @@ -64,12 +64,34 @@ class MobileScanner extends StatefulWidget { | ||
| 64 | /// If this is not null, the barcode scanner will only scan barcodes | 64 | /// If this is not null, the barcode scanner will only scan barcodes |
| 65 | /// which intersect this rectangle. | 65 | /// which intersect this rectangle. |
| 66 | /// | 66 | /// |
| 67 | - /// The rectangle is relative to the layout size of the *camera preview widget*, | ||
| 68 | - /// rather than the actual camera preview size, | ||
| 69 | - /// since the actual widget size might not be the same as the camera preview size. | 67 | + /// This rectangle is relative to the layout size |
| 68 | + /// of the *camera preview widget* in the widget tree, | ||
| 69 | + /// rather than the actual size of the camera preview output. | ||
| 70 | + /// This is because the size of the camera preview widget | ||
| 71 | + /// might not be the same as the size of the camera output. | ||
| 70 | /// | 72 | /// |
| 71 | /// For example, the applied [fit] has an effect on the size of the camera preview widget, | 73 | /// For example, the applied [fit] has an effect on the size of the camera preview widget, |
| 72 | /// while the camera preview size remains the same. | 74 | /// while the camera preview size remains the same. |
| 75 | + /// | ||
| 76 | + /// The following example shows a scan window that is centered, | ||
| 77 | + /// fills half the height and one third of the width of the layout: | ||
| 78 | + /// | ||
| 79 | + /// ```dart | ||
| 80 | + /// LayoutBuider( | ||
| 81 | + /// builder: (BuildContext context, BoxConstraints constraints) { | ||
| 82 | + /// final Size layoutSize = constraints.biggest; | ||
| 83 | + /// | ||
| 84 | + /// final double scanWindowWidth = layoutSize.width / 3; | ||
| 85 | + /// final double scanWindowHeight = layoutSize.height / 2; | ||
| 86 | + /// | ||
| 87 | + /// final Rect scanWindow = Rect.fromCenter( | ||
| 88 | + /// center: layoutSize.center(Offset.zero), | ||
| 89 | + /// width: scanWindowWidth, | ||
| 90 | + /// height: scanWindowHeight, | ||
| 91 | + /// ); | ||
| 92 | + /// } | ||
| 93 | + /// ); | ||
| 94 | + /// ``` | ||
| 73 | final Rect? scanWindow; | 95 | final Rect? scanWindow; |
| 74 | 96 | ||
| 75 | @override | 97 | @override |
| @@ -80,7 +102,9 @@ class _MobileScannerState extends State<MobileScanner> { | @@ -80,7 +102,9 @@ class _MobileScannerState extends State<MobileScanner> { | ||
| 80 | /// The current scan window. | 102 | /// The current scan window. |
| 81 | Rect? scanWindow; | 103 | Rect? scanWindow; |
| 82 | 104 | ||
| 83 | - /// Recalculate the scan window based on the updated [constraints]. | 105 | + /// Calculate the scan window based on the given [constraints]. |
| 106 | + /// | ||
| 107 | + /// If the [scanWindow] is already set, this method does nothing. | ||
| 84 | void _maybeUpdateScanWindow( | 108 | void _maybeUpdateScanWindow( |
| 85 | MobileScannerState scannerState, | 109 | MobileScannerState scannerState, |
| 86 | BoxConstraints constraints, | 110 | BoxConstraints constraints, |
-
Please register or login to post a comment