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
Julian Steenbakker
2022-12-12 15:44:57 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dec683032e19ccf7bf997f70a5d4c47bb470c8c9
dec68303
1 parent
51acc7ac
style: flutter format .
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
21 deletions
example/lib/barcode_scanner_window.dart
lib/src/mobile_scanner.dart
lib/src/objects/barcode_capture.dart
example/lib/barcode_scanner_window.dart
View file @
dec6830
...
...
@@ -26,7 +26,6 @@ class _BarcodeScannerWithScanWindowState
@override
Widget
build
(
BuildContext
context
)
{
final
query
=
MediaQuery
.
of
(
context
);
final
scanWindow
=
Rect
.
fromCenter
(
center:
MediaQuery
.
of
(
context
).
size
.
center
(
Offset
.
zero
),
width:
200
,
...
...
@@ -54,7 +53,13 @@ class _BarcodeScannerWithScanWindowState
barcode
?.
corners
!=
null
&&
arguments
!=
null
)
CustomPaint
(
painter:
BarcodeOverlay
(
barcode
!,
arguments
!,
BoxFit
.
contain
,
MediaQuery
.
of
(
context
).
devicePixelRatio
,
capture
!),
painter:
BarcodeOverlay
(
barcode
!,
arguments
!,
BoxFit
.
contain
,
MediaQuery
.
of
(
context
).
devicePixelRatio
,
capture
!,
),
),
CustomPaint
(
painter:
ScannerOverlay
(
scanWindow
),
...
...
@@ -126,7 +131,13 @@ class ScannerOverlay extends CustomPainter {
}
class
BarcodeOverlay
extends
CustomPainter
{
BarcodeOverlay
(
this
.
barcode
,
this
.
arguments
,
this
.
boxFit
,
this
.
devicePixelRatio
,
this
.
capture
);
BarcodeOverlay
(
this
.
barcode
,
this
.
arguments
,
this
.
boxFit
,
this
.
devicePixelRatio
,
this
.
capture
,
);
final
BarcodeCapture
capture
;
final
Barcode
barcode
;
...
...
@@ -153,13 +164,21 @@ class BarcodeOverlay extends CustomPainter {
horizontalPadding
=
0
;
}
final
ratioWidth
=
(
Platform
.
isIOS
?
capture
.
width
!
:
arguments
.
size
.
width
)/
adjustedSize
.
destination
.
width
;
final
ratioHeight
=
(
Platform
.
isIOS
?
capture
.
height
!
:
arguments
.
size
.
height
)
/
adjustedSize
.
destination
.
height
;
final
ratioWidth
=
(
Platform
.
isIOS
?
capture
.
width
!
:
arguments
.
size
.
width
)
/
adjustedSize
.
destination
.
width
;
final
ratioHeight
=
(
Platform
.
isIOS
?
capture
.
height
!
:
arguments
.
size
.
height
)
/
adjustedSize
.
destination
.
height
;
final
List
<
Offset
>
adjustedOffset
=
[];
for
(
final
offset
in
barcode
.
corners
!)
{
adjustedOffset
.
add
(
Offset
(
offset
.
dx
/
ratioWidth
+
horizontalPadding
,
offset
.
dy
/
ratioHeight
+
verticalPadding
));
adjustedOffset
.
add
(
Offset
(
offset
.
dx
/
ratioWidth
+
horizontalPadding
,
offset
.
dy
/
ratioHeight
+
verticalPadding
,
),
);
}
final
cutoutPath
=
Path
()..
addPolygon
(
adjustedOffset
,
true
);
...
...
lib/src/mobile_scanner.dart
View file @
dec6830
import
'dart:async'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
hide
applyBoxFit
;
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_controller.dart'
;
import
'package:mobile_scanner/src/objects/barcode_capture.dart'
;
...
...
@@ -135,17 +134,18 @@ class _MobileScannerState extends State<MobileScanner>
/// since the textures size and the actuall image (on the texture size) might not be the same, we also need to
/// calculate the scanWindow in terms of percentages of the texture, not pixels.
Rect
calculateScanWindowRelativeToTextureInPercentage
(
BoxFit
fit
,
Rect
scanWindow
,
Size
textureSize
,
Size
widgetSize
,
)
{
BoxFit
fit
,
Rect
scanWindow
,
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
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
...
...
@@ -161,10 +161,14 @@ class _MobileScannerState extends State<MobileScanner>
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
;
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
(
...
...
@@ -197,7 +201,6 @@ class _MobileScannerState extends State<MobileScanner>
_controller
.
updateScanWindow
(
window
);
}
return
ClipRect
(
child:
LayoutBuilder
(
builder:
(
_
,
constraints
)
{
...
...
@@ -219,7 +222,7 @@ class _MobileScannerState extends State<MobileScanner>
);
},
);
}
}
,
);
}
...
...
lib/src/objects/barcode_capture.dart
View file @
dec6830
...
...
@@ -20,6 +20,6 @@ class BarcodeCapture {
required
this
.
barcodes
,
this
.
image
,
this
.
width
,
this
.
height
this
.
height
,
});
}
...
...
Please
register
or
login
to post a comment