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
2023-11-08 11:26:21 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
740001342a7212ca624182014dea23683ace9408
74000134
1 parent
6059e752
implement mobile scanner method channel
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
3 deletions
lib/src/method_channel/mobile_scanner_method_channel.dart
lib/src/method_channel/mobile_scanner_method_channel.dart
View file @
7400013
import
'package:flutter/foundation.dart'
;
import
'dart:async'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:mobile_scanner/src/enums/camera_facing.dart'
;
import
'package:mobile_scanner/src/enums/torch_state.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_platform_interface.dart'
;
/// An implementation of [MobileScannerPlatform] that uses method channels.
class
MethodChannelMobileScanner
extends
MobileScannerPlatform
{
/// The method channel used to interact with the native platform.
@visibleForTesting
final
methodChannel
=
const
MethodChannel
(
'dev.steenbakker.mobile_scanner/scanner/method'
);
final
methodChannel
=
const
MethodChannel
(
'dev.steenbakker.mobile_scanner/scanner/method'
,
);
/// The event channel that sends back scanned barcode events.
@visibleForTesting
final
eventChannel
=
const
EventChannel
(
'dev.steenbakker.mobile_scanner/scanner/event'
);
final
eventChannel
=
const
EventChannel
(
'dev.steenbakker.mobile_scanner/scanner/event'
,
);
Stream
<
Map
<
Object
?,
Object
?>>?
_eventsStream
;
Stream
<
Map
<
Object
?,
Object
?>>
get
eventsStream
{
_eventsStream
??=
eventChannel
.
receiveBroadcastStream
().
cast
<
Map
<
Object
?,
Object
?>>();
return
_eventsStream
!;
}
int
?
_textureId
;
@override
Stream
<
TorchState
>
get
torchStateStream
{
return
eventsStream
.
where
((
event
)
=>
event
[
'name'
]
==
'torchState'
)
.
map
((
event
)
=>
TorchState
.
fromRawValue
(
event
[
'data'
]
as
int
?
??
0
));
}
@override
Stream
<
double
>
get
zoomScaleStateStream
{
return
eventsStream
.
where
((
event
)
=>
event
[
'name'
]
==
'zoomScaleState'
)
.
map
((
event
)
=>
event
[
'data'
]
as
double
?
??
0.0
);
}
@override
Future
<
bool
>
analyzeImage
(
String
path
)
async
{
final
bool
?
result
=
await
methodChannel
.
invokeMethod
<
bool
>(
'analyzeImage'
,
path
,
);
return
result
??
false
;
}
@override
Widget
buildCameraView
()
=>
Texture
(
textureId:
_textureId
!);
@override
Future
<
void
>
resetZoomScale
()
async
{
await
methodChannel
.
invokeMethod
<
void
>(
'resetScale'
);
}
@override
Future
<
void
>
setTorchState
(
TorchState
torchState
)
async
{
await
methodChannel
.
invokeMethod
<
void
>(
'torch'
,
torchState
.
rawValue
);
}
@override
Future
<
void
>
setZoomScale
(
double
zoomScale
)
async
{
await
methodChannel
.
invokeMethod
<
void
>(
'setScale'
,
zoomScale
);
}
@override
Future
<
void
>
start
(
CameraFacing
cameraDirection
)
{}
@override
Future
<
void
>
stop
()
async
{
await
methodChannel
.
invokeMethod
<
void
>(
'stop'
);
}
@override
Future
<
void
>
updateScanWindow
(
Rect
?
window
)
async
{
await
methodChannel
.
invokeMethod
<
void
>(
'updateScanWindow'
,
{
'rect'
:
window
},
);
}
@override
Future
<
void
>
dispose
()
async
{
await
stop
();
}
}
...
...
Please
register
or
login
to post a comment