Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2024-03-06 13:17:13 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
985b25e339e81b8121db891864a572582c00f708
985b25e3
1 parent
ad68fda9
port scan window update fix to the new beta release
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
7 deletions
CHANGELOG.md
lib/src/mobile_scanner.dart
CHANGELOG.md
View file @
985b25e
## NEXT
Bugs fixed:
*
Fixed an issue where the scan window was not updated when its size was changed. (thanks @navaronbracke !)
## 5.0.0-beta.1
**BREAKING CHANGES:**
...
...
lib/src/mobile_scanner.dart
View file @
985b25e
...
...
@@ -24,6 +24,7 @@ class MobileScanner extends StatefulWidget {
this
.
overlayBuilder
,
this
.
placeholderBuilder
,
this
.
scanWindow
,
this
.
scanWindowUpdateThreshold
=
0.0
,
super
.
key
,
});
...
...
@@ -94,6 +95,19 @@ class MobileScanner extends StatefulWidget {
/// ```
final
Rect
?
scanWindow
;
/// The threshold for updates to the [scanWindow].
///
/// If the [scanWindow] would be updated,
/// due to new layout constraints for the scanner,
/// and the width or height of the new scan window have not changed by this threshold,
/// then the scan window is not updated.
///
/// It is recommended to set this threshold
/// if scan window updates cause performance issues.
///
/// Defaults to no threshold for scan window updates.
final
double
scanWindowUpdateThreshold
;
@override
State
<
MobileScanner
>
createState
()
=>
_MobileScannerState
();
}
...
...
@@ -109,13 +123,49 @@ class _MobileScannerState extends State<MobileScanner> {
MobileScannerState
scannerState
,
BoxConstraints
constraints
,
)
{
if
(
widget
.
scanWindow
!=
null
&&
scanWindow
==
null
)
{
scanWindow
=
calculateScanWindowRelativeToTextureInPercentage
(
widget
.
fit
,
widget
.
scanWindow
!,
textureSize:
scannerState
.
size
,
widgetSize:
constraints
.
biggest
,
);
if
(
widget
.
scanWindow
==
null
)
{
return
;
}
final
Rect
newScanWindow
=
calculateScanWindowRelativeToTextureInPercentage
(
widget
.
fit
,
widget
.
scanWindow
!,
textureSize:
scannerState
.
size
,
widgetSize:
constraints
.
biggest
,
);
// The scan window was never set before.
// Set the initial scan window.
if
(
scanWindow
==
null
)
{
scanWindow
=
newScanWindow
;
unawaited
(
widget
.
controller
.
updateScanWindow
(
scanWindow
));
return
;
}
// The scan window did not not change.
// The left, right, top and bottom are the same.
if
(
scanWindow
==
newScanWindow
)
{
return
;
}
// The update threshold is not set, allow updating the scan window.
if
(
widget
.
scanWindowUpdateThreshold
==
0.0
)
{
scanWindow
=
newScanWindow
;
unawaited
(
widget
.
controller
.
updateScanWindow
(
scanWindow
));
return
;
}
final
double
dx
=
(
newScanWindow
.
width
-
scanWindow
!.
width
).
abs
();
final
double
dy
=
(
newScanWindow
.
height
-
scanWindow
!.
height
).
abs
();
// The new scan window has changed enough, allow updating the scan window.
if
(
dx
>=
widget
.
scanWindowUpdateThreshold
||
dy
>=
widget
.
scanWindowUpdateThreshold
)
{
scanWindow
=
newScanWindow
;
unawaited
(
widget
.
controller
.
updateScanWindow
(
scanWindow
));
}
...
...
Please
register
or
login
to post a comment