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
Saeed
2023-06-26 14:38:36 +0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
420e00fade5079678881dff8be144fea2272e9b9
420e00fa
1 parent
5aa2c119
improved accuracy
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
38 deletions
lib/src/mobile_scanner.dart
lib/src/mobile_scanner.dart
View file @
420e00f
...
...
@@ -188,44 +188,59 @@ class _MobileScannerState extends State<MobileScanner>
Size
textureSize
,
Size
widgetSize
,
)
{
/// map the texture size to get its new size after fitted to screen
final
fittedTextureSize
=
applyBoxFit
(
fit
,
textureSize
,
widgetSize
);
/// create a new rectangle that represents the texture on the screen
final
minX
=
widgetSize
.
width
/
2
-
fittedTextureSize
.
destination
.
width
/
2
;
final
minY
=
widgetSize
.
height
/
2
-
fittedTextureSize
.
destination
.
height
/
2
;
final
textureWindow
=
Offset
(
minX
,
minY
)
&
fittedTextureSize
.
destination
;
/// create a new scan window and with only the area of the rect intersecting the texture window
final
scanWindowInTexture
=
scanWindow
.
intersect
(
textureWindow
);
/// update the scanWindow left and top to be relative to the texture not the widget
final
newLeft
=
scanWindowInTexture
.
left
-
textureWindow
.
left
;
final
newTop
=
scanWindowInTexture
.
top
-
textureWindow
.
top
;
final
newWidth
=
scanWindowInTexture
.
width
;
final
newHeight
=
scanWindowInTexture
.
height
;
/// new scanWindow that is adapted to the boxfit and relative to the texture
final
windowInTexture
=
Rect
.
fromLTWH
(
newLeft
,
newTop
,
newWidth
,
newHeight
);
/// get the scanWindow as a percentage of the texture
final
percentageLeft
=
windowInTexture
.
left
/
fittedTextureSize
.
destination
.
width
;
final
percentageTop
=
windowInTexture
.
top
/
fittedTextureSize
.
destination
.
height
;
final
percentageRight
=
windowInTexture
.
right
/
fittedTextureSize
.
destination
.
width
;
final
percentagebottom
=
windowInTexture
.
bottom
/
fittedTextureSize
.
destination
.
height
;
/// this rectangle can be send to native code and used to cut out a rectangle of the scan image
return
Rect
.
fromLTRB
(
percentageLeft
,
percentageTop
,
percentageRight
,
percentagebottom
,
);
double
fittedTextureWidth
;
double
fittedTextureHeight
;
switch
(
fit
)
{
case
BoxFit
.
contain
:
final
widthRatio
=
widgetSize
.
width
/
textureSize
.
width
;
final
heightRatio
=
widgetSize
.
height
/
textureSize
.
height
;
final
scale
=
widthRatio
<
heightRatio
?
widthRatio
:
heightRatio
;
fittedTextureWidth
=
textureSize
.
width
*
scale
;
fittedTextureHeight
=
textureSize
.
height
*
scale
;
break
;
case
BoxFit
.
cover
:
final
widthRatio
=
widgetSize
.
width
/
textureSize
.
width
;
final
heightRatio
=
widgetSize
.
height
/
textureSize
.
height
;
final
scale
=
widthRatio
>
heightRatio
?
widthRatio
:
heightRatio
;
fittedTextureWidth
=
textureSize
.
width
*
scale
;
fittedTextureHeight
=
textureSize
.
height
*
scale
;
break
;
case
BoxFit
.
fill
:
fittedTextureWidth
=
widgetSize
.
width
;
fittedTextureHeight
=
widgetSize
.
height
;
break
;
case
BoxFit
.
fitHeight
:
final
ratio
=
widgetSize
.
height
/
textureSize
.
height
;
fittedTextureWidth
=
textureSize
.
width
*
ratio
;
fittedTextureHeight
=
widgetSize
.
height
;
break
;
case
BoxFit
.
fitWidth
:
final
ratio
=
widgetSize
.
width
/
textureSize
.
width
;
fittedTextureWidth
=
widgetSize
.
width
;
fittedTextureHeight
=
textureSize
.
height
*
ratio
;
break
;
case
BoxFit
.
none
:
case
BoxFit
.
scaleDown
:
fittedTextureWidth
=
textureSize
.
width
;
fittedTextureHeight
=
textureSize
.
height
;
break
;
}
final
offsetX
=
(
widgetSize
.
width
-
fittedTextureWidth
)
/
2
;
final
offsetY
=
(
widgetSize
.
height
-
fittedTextureHeight
)
/
2
;
final
left
=
(
scanWindow
.
left
-
offsetX
)
/
fittedTextureWidth
;
final
top
=
(
scanWindow
.
top
-
offsetY
)
/
fittedTextureHeight
;
final
right
=
(
scanWindow
.
right
-
offsetX
)
/
fittedTextureWidth
;
final
bottom
=
(
scanWindow
.
bottom
-
offsetY
)
/
fittedTextureHeight
;
return
Rect
.
fromLTRB
(
left
,
top
,
right
,
bottom
);
}
Rect
?
scanWindow
;
...
...
@@ -259,6 +274,7 @@ class _MobileScannerState extends State<MobileScanner>
size:
constraints
.
biggest
,
child:
FittedBox
(
fit:
widget
.
fit
,
// alignment: Alignment.topCenter,
child:
SizedBox
(
width:
value
.
size
.
width
,
height:
value
.
size
.
height
,
...
...
Please
register
or
login
to post a comment