buildWidget method
build your widget here
Implementation
@override
Widget buildWidget(BuildContext context) {
final cutOutHeight =
Utils.getDouble(widget.controller.cutOutHeight, fallback: 200);
final cutOutWidth =
Utils.getDouble(widget.controller.cutOutWidth, fallback: 200);
return EnsembleBoxWrapper(
boxController: widget.controller,
widget: LayoutBuilder(
builder: (context, constraints) {
final layoutSize = constraints.biggest;
final scanWindow =
_scanWindowForLayout(layoutSize, cutOutWidth, cutOutHeight);
final isLandscape = layoutSize.width > layoutSize.height;
// Native scanWindow has incorrect hit-testing in landscape on some
// devices (mobile_scanner#1633). Scan the full preview instead; the
// overlay cutout is visual-only in landscape.
final useNativeScanWindow = !kIsWeb && !isLandscape;
return MobileScanner(
key: qrKey,
controller: scannerController,
scanWindow: useNativeScanWindow ? scanWindow : null,
onDetect: (capture) {
if (capture.barcodes.isNotEmpty &&
widget.controller.onReceived != null) {
final barcode = capture.barcodes.first;
final data = {
'format': barcode.format.name,
'data': barcode.rawValue,
// Keep the existing event payload compatible with the
// mobile_scanner version resolved by the workspace.
// ignore: deprecated_member_use
'rawBytes': barcode.rawBytes,
};
ScreenController().executeAction(
context,
widget.controller.onReceived!,
event: EnsembleEvent(widget.controller, data: data),
);
}
},
overlayBuilder: (context, overlayConstraints) {
return CustomPaint(
painter: QRScannerOverlayPainter(
borderColor:
widget.controller.cutOutBorderColor ?? Colors.red,
borderRadius: Utils.getDouble(
widget.controller.cutOutBorderRadius,
fallback: 0,
),
cutOutWidth: cutOutWidth,
cutOutHeight: cutOutHeight,
),
child: const SizedBox.expand(),
);
},
);
},
),
);
}