Committed by
GitHub
Merge pull request #671 from svenopdehipt/overlay
feat: Add overlay to scanner
Showing
1 changed file
with
30 additions
and
17 deletions
| @@ -62,6 +62,10 @@ class MobileScanner extends StatefulWidget { | @@ -62,6 +62,10 @@ class MobileScanner extends StatefulWidget { | ||
| 62 | /// Default: false | 62 | /// Default: false |
| 63 | final bool startDelay; | 63 | final bool startDelay; |
| 64 | 64 | ||
| 65 | + /// The overlay which will be painted above the scanner when has started successful. | ||
| 66 | + /// Will no be pointed when an error occurs or the scanner hasn't be started yet. | ||
| 67 | + final Widget? overlay; | ||
| 68 | + | ||
| 65 | /// Create a new [MobileScanner] using the provided [controller] | 69 | /// Create a new [MobileScanner] using the provided [controller] |
| 66 | /// and [onBarcodeDetected] callback. | 70 | /// and [onBarcodeDetected] callback. |
| 67 | const MobileScanner({ | 71 | const MobileScanner({ |
| @@ -74,6 +78,7 @@ class MobileScanner extends StatefulWidget { | @@ -74,6 +78,7 @@ class MobileScanner extends StatefulWidget { | ||
| 74 | this.placeholderBuilder, | 78 | this.placeholderBuilder, |
| 75 | this.scanWindow, | 79 | this.scanWindow, |
| 76 | this.startDelay = false, | 80 | this.startDelay = false, |
| 81 | + this.overlay, | ||
| 77 | super.key, | 82 | super.key, |
| 78 | }); | 83 | }); |
| 79 | 84 | ||
| @@ -251,24 +256,32 @@ class _MobileScannerState extends State<MobileScanner> | @@ -251,24 +256,32 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 251 | _controller.updateScanWindow(scanWindow); | 256 | _controller.updateScanWindow(scanWindow); |
| 252 | } | 257 | } |
| 253 | 258 | ||
| 254 | - return ClipRect( | ||
| 255 | - child: LayoutBuilder( | ||
| 256 | - builder: (_, constraints) { | ||
| 257 | - return SizedBox.fromSize( | ||
| 258 | - size: constraints.biggest, | ||
| 259 | - child: FittedBox( | ||
| 260 | - fit: widget.fit, | ||
| 261 | - child: SizedBox.fromSize( | ||
| 262 | - size: value.size, | ||
| 263 | - child: kIsWeb | ||
| 264 | - ? HtmlElementView(viewType: value.webId!) | ||
| 265 | - : Texture(textureId: value.textureId!), | 259 | + return Stack( |
| 260 | + alignment: Alignment.center, | ||
| 261 | + children: [ | ||
| 262 | + ClipRect( | ||
| 263 | + child: LayoutBuilder( | ||
| 264 | + builder: (_, constraints) { | ||
| 265 | + return SizedBox.fromSize( | ||
| 266 | + size: constraints.biggest, | ||
| 267 | + child: FittedBox( | ||
| 268 | + fit: widget.fit, | ||
| 269 | + child: SizedBox( | ||
| 270 | + width: value.size.width, | ||
| 271 | + height: value.size.height, | ||
| 272 | + child: kIsWeb | ||
| 273 | + ? HtmlElementView(viewType: value.webId!) | ||
| 274 | + : Texture(textureId: value.textureId!), | ||
| 275 | + ), | ||
| 276 | + ), | ||
| 277 | + ); | ||
| 278 | + }, | ||
| 266 | ), | 279 | ), |
| 267 | ), | 280 | ), |
| 268 | - ); | ||
| 269 | - }, | ||
| 270 | - ), | ||
| 271 | - ); | 281 | + if (widget.overlay != null) |
| 282 | + widget.overlay! | ||
| 283 | + ], | ||
| 284 | + ); | ||
| 272 | }, | 285 | }, |
| 273 | ); | 286 | ); |
| 274 | } | 287 | } |
| @@ -282,4 +295,4 @@ class _MobileScannerState extends State<MobileScanner> | @@ -282,4 +295,4 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 282 | _controller.dispose(); | 295 | _controller.dispose(); |
| 283 | super.dispose(); | 296 | super.dispose(); |
| 284 | } | 297 | } |
| 285 | -} | 298 | +} |
-
Please register or login to post a comment