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-09-28 20:01:20 +0200
Browse Files
Options
Browse Files
Download
Plain Diff
Committed by
GitHub
2022-09-28 20:01:20 +0200
Commit
3b64908a27a3263cba88e5e0126a51430dd9e726
3b64908a
2 parents
d18df020
8e81c191
Merge branch 'master' into dependabot/github_actions/actions/setup-java-3.5.1
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
37 additions
and
17 deletions
.github/workflows/flutter.yml
android/build.gradle
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
example/android/app/src/main/AndroidManifest.xml
example/android/app/src/main/kotlin/dev/steenbakker/mobile_scanner_example/MainActivity.kt
example/android/build.gradle
ios/Classes/SwiftMobileScannerPlugin.swift
lib/mobile_scanner_web_plugin.dart
lib/src/mobile_scanner.dart
lib/src/mobile_scanner_controller.dart
.github/workflows/flutter.yml
View file @
3b64908
...
...
@@ -16,7 +16,7 @@ jobs:
with
:
java-version
:
11
distribution
:
temurin
-
uses
:
subosito/flutter-action@v2.
6
.1
-
uses
:
subosito/flutter-action@v2.
7
.1
with
:
cache
:
true
-
name
:
Version
...
...
@@ -33,7 +33,7 @@ jobs:
with
:
java-version
:
11
distribution
:
temurin
-
uses
:
subosito/flutter-action@v2.
6
.1
-
uses
:
subosito/flutter-action@v2.
7
.1
with
:
cache
:
true
-
name
:
Format
...
...
android/build.gradle
View file @
3b64908
...
...
@@ -9,7 +9,7 @@ buildscript {
}
dependencies
{
classpath
'com.android.tools.build:gradle:7.
2.2
'
classpath
'com.android.tools.build:gradle:7.
3.0
'
}
}
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
3b64908
...
...
@@ -29,7 +29,11 @@ import java.io.File
class MobileScanner(private val activity: Activity, private val textureRegistry: TextureRegistry)
: MethodChannel.MethodCallHandler, EventChannel.StreamHandler, PluginRegistry.RequestPermissionsResultListener {
companion object {
private const val REQUEST_CODE = 22022022
/**
* When the application's activity is [androidx.fragment.app.FragmentActivity], requestCode can only use the lower 16 bits.
* @see androidx.fragment.app.FragmentActivity.validateRequestPermissionsRequestCode
*/
private const val REQUEST_CODE = 0x0786
private val TAG = MobileScanner::class.java.simpleName
}
...
...
example/android/app/src/main/AndroidManifest.xml
View file @
3b64908
...
...
@@ -5,7 +5,7 @@
android:label=
"mobile_scanner_example"
android:icon=
"@mipmap/ic_launcher"
>
<activity
android:name=
"
io.flutter.embedding.android.Flutter
Activity"
android:name=
"
.Main
Activity"
android:exported=
"true"
android:launchMode=
"singleTop"
android:theme=
"@style/LaunchTheme"
...
...
example/android/app/src/main/kotlin/dev/steenbakker/mobile_scanner_example/MainActivity.kt
View file @
3b64908
package dev.steenbakker.mobile_scanner_example
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.Flutter
Fragment
Activity
class MainActivity
: Flutter
Activity() {
class MainActivity
: FlutterFragment
Activity() {
}
...
...
example/android/build.gradle
View file @
3b64908
...
...
@@ -6,7 +6,7 @@ buildscript {
}
dependencies
{
classpath
'com.android.tools.build:gradle:7.
2.2
'
classpath
'com.android.tools.build:gradle:7.
3.0
'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
...
...
ios/Classes/SwiftMobileScannerPlugin.swift
View file @
3b64908
...
...
@@ -195,13 +195,13 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan
let
facing
:
Int
=
argReader
.
int
(
key
:
"facing"
)
??
1
let
formats
:
Array
=
argReader
.
intArray
(
key
:
"formats"
)
??
[]
let
formatList
:
NSMutableArray
=
[]
if
(
formats
.
count
!=
0
)
{
var
barcodeFormats
:
BarcodeFormat
=
[]
for
index
in
formats
{
formatList
.
add
(
BarcodeFormat
(
rawValue
:
index
))
barcodeFormats
.
insert
(
BarcodeFormat
(
rawValue
:
index
))
}
if
(
formatList
.
count
!=
0
)
{
let
barcodeOptions
=
BarcodeScannerOptions
(
formats
:
formatList
.
firstObject
as!
BarcodeFormat
)
let
barcodeOptions
=
BarcodeScannerOptions
(
formats
:
barcodeFormats
)
scanner
=
BarcodeScanner
.
barcodeScanner
(
options
:
barcodeOptions
)
}
...
...
lib/mobile_scanner_web_plugin.dart
View file @
3b64908
...
...
@@ -24,7 +24,6 @@ class MobileScannerWebPlugin {
registrar
,
);
final
MobileScannerWebPlugin
instance
=
MobileScannerWebPlugin
();
WidgetsFlutterBinding
.
ensureInitialized
();
channel
.
setMethodCallHandler
(
instance
.
handleMethodCall
);
event
.
setController
(
instance
.
controller
);
...
...
lib/src/mobile_scanner.dart
View file @
3b64908
...
...
@@ -9,6 +9,9 @@ class MobileScanner extends StatefulWidget {
/// The controller of the camera.
final
MobileScannerController
?
controller
;
/// Calls the provided [onPermissionSet] callback when the permission is set.
final
Function
(
bool
permissionGranted
)?
onPermissionSet
;
/// Function that gets called when a Barcode is detected.
///
/// [barcode] The barcode object with all information about the scanned code.
...
...
@@ -34,6 +37,7 @@ class MobileScanner extends StatefulWidget {
this
.
controller
,
this
.
fit
=
BoxFit
.
cover
,
this
.
allowDuplicates
=
false
,
this
.
onPermissionSet
,
});
@override
...
...
@@ -48,7 +52,8 @@ class _MobileScannerState extends State<MobileScanner>
void
initState
()
{
super
.
initState
();
WidgetsBinding
.
instance
.
addObserver
(
this
);
controller
=
widget
.
controller
??
MobileScannerController
();
controller
=
widget
.
controller
??
MobileScannerController
(
onPermissionSet:
widget
.
onPermissionSet
);
if
(!
controller
.
isStarting
)
controller
.
start
();
}
...
...
@@ -118,7 +123,8 @@ class _MobileScannerState extends State<MobileScanner>
}
}
else
{
if
(
widget
.
controller
==
null
)
{
controller
=
MobileScannerController
();
controller
=
MobileScannerController
(
onPermissionSet:
widget
.
onPermissionSet
);
}
else
if
(
oldWidget
.
controller
!=
widget
.
controller
)
{
controller
=
widget
.
controller
!;
}
...
...
lib/src/mobile_scanner_controller.dart
View file @
3b64908
...
...
@@ -39,6 +39,7 @@ class MobileScannerController {
static
int
?
_controllerHashcode
;
StreamSubscription
?
events
;
Function
(
bool
permissionGranted
)?
onPermissionSet
;
final
ValueNotifier
<
MobileScannerArguments
?>
args
=
ValueNotifier
(
null
);
final
ValueNotifier
<
TorchState
>
torchState
=
ValueNotifier
(
TorchState
.
off
);
late
final
ValueNotifier
<
CameraFacing
>
cameraFacingState
;
...
...
@@ -48,8 +49,6 @@ class MobileScannerController {
final
bool
returnImage
;
/// If provided, the scanner will only detect those specific formats.
///
/// WARNING: On iOS, only 1 format is supported.
final
List
<
BarcodeFormat
>?
formats
;
CameraFacing
facing
;
...
...
@@ -66,6 +65,7 @@ class MobileScannerController {
this
.
ratio
,
this
.
torchEnabled
,
this
.
formats
,
this
.
onPermissionSet
,
this
.
autoResume
=
true
,
this
.
returnImage
=
false
,
})
{
...
...
@@ -156,11 +156,14 @@ class MobileScannerController {
state
=
result
?
MobileScannerState
.
authorized
:
MobileScannerState
.
denied
;
onPermissionSet
?.
call
(
result
);
break
;
case
MobileScannerState
.
denied
:
isStarting
=
false
;
onPermissionSet
?.
call
(
false
);
throw
PlatformException
(
code:
'NO ACCESS'
);
case
MobileScannerState
.
authorized
:
onPermissionSet
?.
call
(
true
);
break
;
}
}
...
...
@@ -192,6 +195,9 @@ class MobileScannerController {
}
on
PlatformException
catch
(
error
)
{
debugPrint
(
'
${error.code}
:
${error.message}
'
);
isStarting
=
false
;
if
(
error
.
code
==
"MobileScannerWeb"
)
{
onPermissionSet
?.
call
(
false
);
}
// setAnalyzeMode(AnalyzeMode.none.index);
return
;
}
...
...
@@ -204,6 +210,10 @@ class MobileScannerController {
hasTorch
=
startResult
[
'torchable'
]
as
bool
?
??
false
;
if
(
kIsWeb
)
{
onPermissionSet
?.
call
(
true
,
);
// If we reach this line, it means camera permission has been granted
args
.
value
=
MobileScannerArguments
(
webId:
startResult
[
'ViewID'
]
as
String
?,
size:
Size
(
...
...
@@ -287,6 +297,7 @@ class MobileScannerController {
events
?.
cancel
();
events
=
null
;
_controllerHashcode
=
null
;
onPermissionSet
=
null
;
}
barcodesController
.
close
();
}
...
...
Please
register
or
login
to post a comment