Julian Steenbakker
Committed by GitHub

Merge branch 'master' into dependabot/github_actions/actions/setup-java-3.5.1

... ... @@ -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
... ...
... ... @@ -9,7 +9,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.android.tools.build:gradle:7.3.0'
}
}
... ...
... ... @@ -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
}
... ...
... ... @@ -5,7 +5,7 @@
android:label="mobile_scanner_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name="io.flutter.embedding.android.FlutterActivity"
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
... ...
package dev.steenbakker.mobile_scanner_example
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterActivity() {
class MainActivity : FlutterFragmentActivity() {
}
... ...
... ... @@ -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"
}
}
... ...
... ... @@ -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)
}
... ...
... ... @@ -24,7 +24,6 @@ class MobileScannerWebPlugin {
registrar,
);
final MobileScannerWebPlugin instance = MobileScannerWebPlugin();
WidgetsFlutterBinding.ensureInitialized();
channel.setMethodCallHandler(instance.handleMethodCall);
event.setController(instance.controller);
... ...
... ... @@ -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!;
}
... ...
... ... @@ -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();
}
... ...