Skip to content

Commit

Permalink
Merge pull request #753 from jlin5/issue_745
Browse files Browse the repository at this point in the history
fix: Add back LayoutBuilder to calculate the correct widgetSize
  • Loading branch information
juliansteenbakker authored Sep 26, 2023
2 parents 8d7a063 + b24afed commit 128ce4b
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions lib/src/mobile_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,36 +248,38 @@ class _MobileScannerState extends State<MobileScanner>

@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;

return ValueListenableBuilder<MobileScannerArguments?>(
valueListenable: _controller.startArguments,
builder: (context, value, child) {
if (value == null) {
return _buildPlaceholderOrError(context, child);
}

if (widget.scanWindow != null && scanWindow == null) {
scanWindow = calculateScanWindowRelativeToTextureInPercentage(
widget.fit,
widget.scanWindow!,
value.size,
size,
);

_controller.updateScanWindow(scanWindow);
}
if (widget.overlay != null) {
return Stack(
alignment: Alignment.center,
children: [
_scanner(value.size, value.webId, value.textureId),
widget.overlay!,
],
);
} else {
return _scanner(value.size, value.webId, value.textureId);
}
return LayoutBuilder(
builder: (context, constraints) {
return ValueListenableBuilder<MobileScannerArguments?>(
valueListenable: _controller.startArguments,
builder: (context, value, child) {
if (value == null) {
return _buildPlaceholderOrError(context, child);
}

if (widget.scanWindow != null && scanWindow == null) {
scanWindow = calculateScanWindowRelativeToTextureInPercentage(
widget.fit,
widget.scanWindow!,
value.size,
Size(constraints.maxWidth, constraints.maxHeight),
);

_controller.updateScanWindow(scanWindow);
}
if (widget.overlay != null) {
return Stack(
alignment: Alignment.center,
children: [
_scanner(value.size, value.webId, value.textureId),
widget.overlay!,
],
);
} else {
return _scanner(value.size, value.webId, value.textureId);
}
},
);
},
);
}
Expand Down

0 comments on commit 128ce4b

Please sign in to comment.