Sven Op de Hipt

add overlay to scanner

@@ -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
@@ -252,7 +257,10 @@ class _MobileScannerState extends State<MobileScanner> @@ -252,7 +257,10 @@ class _MobileScannerState extends State<MobileScanner>
252 _controller.updateScanWindow(scanWindow); 257 _controller.updateScanWindow(scanWindow);
253 } 258 }
254 259
255 - return ClipRect( 260 + return Stack(
  261 + alignment: Alignment.center,
  262 + children: [
  263 + ClipRect(
256 child: LayoutBuilder( 264 child: LayoutBuilder(
257 builder: (_, constraints) { 265 builder: (_, constraints) {
258 return SizedBox.fromSize( 266 return SizedBox.fromSize(
@@ -270,6 +278,10 @@ class _MobileScannerState extends State<MobileScanner> @@ -270,6 +278,10 @@ class _MobileScannerState extends State<MobileScanner>
270 ); 278 );
271 }, 279 },
272 ), 280 ),
  281 + ),
  282 + if (widget.overlay != null)
  283 + widget.overlay!
  284 + ],
273 ); 285 );
274 }, 286 },
275 ); 287 );