imp: upgrade compile sdk, fix custom frameflutter-beta
| @@ -1 +1 @@ | |||
| include: package:pedantic/analysis_options.yaml | |||
| include: package:flutter_lints/flutter.yaml | |||
| @@ -2,14 +2,14 @@ group 'net.touchcapture.qr.flutterqr' | |||
| version '1.0-SNAPSHOT' | |||
| buildscript { | |||
| ext.kotlin_version = '1.5.10' | |||
| ext.kotlin_version = '1.5.31' | |||
| repositories { | |||
| google() | |||
| mavenCentral() | |||
| } | |||
| dependencies { | |||
| classpath 'com.android.tools.build:gradle:4.2.1' | |||
| classpath 'com.android.tools.build:gradle:7.0.2' | |||
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |||
| } | |||
| } | |||
| @@ -36,9 +36,7 @@ android { | |||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |||
| multiDexEnabled true | |||
| } | |||
| buildFeatures { | |||
| viewBinding = true | |||
| } | |||
| compileOptions { | |||
| // Flag to enable support for the new language APIs | |||
| coreLibraryDesugaringEnabled true | |||
| @@ -1,4 +1,4 @@ | |||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.touchcapture.qr.flutterqr" | |||
| xmlns:tools="http://schemas.android.com/tools"> | |||
| <manifest package="net.touchcapture.qr.flutterqr" | |||
| xmlns:tools="http://schemas.android.com/tools"> | |||
| <uses-sdk tools:overrideLibrary="com.google.zxing.client.android" /> | |||
| </manifest> | |||
| @@ -1,50 +0,0 @@ | |||
| package net.touchcapture.qr.flutterqr; | |||
| import android.content.Context; | |||
| import android.graphics.Rect; | |||
| import android.util.AttributeSet; | |||
| import com.journeyapps.barcodescanner.BarcodeView; | |||
| import com.journeyapps.barcodescanner.Size; | |||
| public class CustomFramingRectBarcodeView extends BarcodeView { | |||
| private static final int BOTTOM_OFFSET_NOT_SET_VALUE = -1; | |||
| private int bottomOffset = BOTTOM_OFFSET_NOT_SET_VALUE; | |||
| public CustomFramingRectBarcodeView(Context context) { | |||
| super(context); | |||
| } | |||
| public CustomFramingRectBarcodeView(Context context, AttributeSet attrs) { | |||
| super(context, attrs); | |||
| } | |||
| public CustomFramingRectBarcodeView(Context context, AttributeSet attrs, int defStyleAttr) { | |||
| super(context, attrs, defStyleAttr); | |||
| } | |||
| @Override | |||
| protected Rect calculateFramingRect(Rect container, Rect surface) { | |||
| Rect containerArea = new Rect(container); | |||
| boolean intersects = containerArea.intersect(surface);//adjusts the containerArea (code from super.calculateFramingRect) | |||
| Rect scanAreaRect = super.calculateFramingRect(container, surface); | |||
| if (bottomOffset != BOTTOM_OFFSET_NOT_SET_VALUE) {//if the setFramingRect function was called, then we shift the scan area by Y | |||
| Rect scanAreaRectWithOffset = new Rect(scanAreaRect); | |||
| scanAreaRectWithOffset.bottom -= bottomOffset; | |||
| scanAreaRectWithOffset.top -= bottomOffset; | |||
| boolean belongsToContainer = scanAreaRectWithOffset.intersect(containerArea); | |||
| if(belongsToContainer){ | |||
| return scanAreaRectWithOffset; | |||
| } | |||
| } | |||
| return scanAreaRect; | |||
| } | |||
| public void setFramingRect(int rectWidth, int rectHeight, int bottomOffset) { | |||
| this.bottomOffset = bottomOffset; | |||
| this.setFramingRectSize(new Size(rectWidth, rectHeight)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,45 @@ | |||
| package net.touchcapture.qr.flutterqr | |||
| import android.content.Context | |||
| import android.graphics.Rect | |||
| import android.util.AttributeSet | |||
| import com.journeyapps.barcodescanner.BarcodeView | |||
| import com.journeyapps.barcodescanner.Size | |||
| class CustomFramingRectBarcodeView : BarcodeView { | |||
| private var bottomOffset = BOTTOM_OFFSET_NOT_SET_VALUE | |||
| constructor(context: Context?) : super(context) {} | |||
| constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {} | |||
| constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super( | |||
| context, | |||
| attrs, | |||
| defStyleAttr | |||
| ) | |||
| override fun calculateFramingRect(container: Rect, surface: Rect): Rect { | |||
| val containerArea = Rect(container) | |||
| val intersects = | |||
| containerArea.intersect(surface) //adjusts the containerArea (code from super.calculateFramingRect) | |||
| val scanAreaRect = super.calculateFramingRect(container, surface) | |||
| if (bottomOffset != BOTTOM_OFFSET_NOT_SET_VALUE) { //if the setFramingRect function was called, then we shift the scan area by Y | |||
| val scanAreaRectWithOffset = Rect(scanAreaRect) | |||
| scanAreaRectWithOffset.bottom -= bottomOffset | |||
| scanAreaRectWithOffset.top -= bottomOffset | |||
| val belongsToContainer = scanAreaRectWithOffset.intersect(containerArea) | |||
| if (belongsToContainer) { | |||
| return scanAreaRectWithOffset | |||
| } | |||
| } | |||
| return scanAreaRect | |||
| } | |||
| fun setFramingRect(rectWidth: Int, rectHeight: Int, bottomOffset: Int) { | |||
| this.bottomOffset = bottomOffset | |||
| framingRectSize = Size(rectWidth, rectHeight) | |||
| } | |||
| companion object { | |||
| private const val BOTTOM_OFFSET_NOT_SET_VALUE = -1 | |||
| } | |||
| } | |||
| @@ -1,65 +1,43 @@ | |||
| package net.touchcapture.qr.flutterqr | |||
| import android.app.Activity | |||
| import android.content.pm.PackageManager | |||
| import androidx.annotation.NonNull | |||
| import io.flutter.embedding.engine.plugins.FlutterPlugin | |||
| import io.flutter.embedding.engine.plugins.activity.ActivityAware | |||
| import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding | |||
| import io.flutter.plugin.common.BinaryMessenger | |||
| import io.flutter.plugin.common.PluginRegistry | |||
| import io.flutter.plugin.platform.PlatformViewRegistry | |||
| import net.touchcapture.qr.flutterqr.Shared.activity | |||
| class FlutterQrPlugin : FlutterPlugin, ActivityAware { | |||
| /** Plugin registration embedding v1 */ | |||
| companion object { | |||
| @JvmStatic | |||
| fun registerWith(registrar: PluginRegistry.Registrar) { | |||
| FlutterQrPlugin().onAttachedToV1(registrar) | |||
| } | |||
| } | |||
| private fun onAttachedToV1(registrar: PluginRegistry.Registrar) { | |||
| Shared.registrar = registrar | |||
| onAttachedToEngines(registrar.platformViewRegistry(), registrar.messenger(), registrar.activity()) | |||
| } | |||
| /** Plugin registration embedding v2 */ | |||
| override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | |||
| onAttachedToEngines(flutterPluginBinding.platformViewRegistry, flutterPluginBinding.binaryMessenger, Shared.activity) | |||
| if (activity != null) { | |||
| activity = activity | |||
| } | |||
| flutterPluginBinding.platformViewRegistry | |||
| .registerViewFactory( | |||
| "net.touchcapture.qr.flutterqr/qrview", QRViewFactory(flutterPluginBinding.binaryMessenger)) | |||
| } | |||
| override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | |||
| } | |||
| /** Plugin start for both embedding v1 & v2 */ | |||
| private fun onAttachedToEngines(platformViewRegistry: PlatformViewRegistry, messenger: BinaryMessenger, activity: Activity?) { | |||
| if (activity != null) { | |||
| Shared.activity = activity | |||
| } | |||
| platformViewRegistry | |||
| .registerViewFactory( | |||
| "net.touchcapture.qr.flutterqr/qrview", QRViewFactory(messenger)) | |||
| } | |||
| override fun onAttachedToActivity(activityPluginBinding: ActivityPluginBinding) { | |||
| Shared.activity = activityPluginBinding.activity | |||
| activity = activityPluginBinding.activity | |||
| Shared.binding = activityPluginBinding | |||
| } | |||
| override fun onDetachedFromActivityForConfigChanges() { | |||
| Shared.activity = null | |||
| activity = null | |||
| Shared.binding = null | |||
| } | |||
| override fun onReattachedToActivityForConfigChanges(activityPluginBinding: ActivityPluginBinding) { | |||
| Shared.activity = activityPluginBinding.activity | |||
| activity = activityPluginBinding.activity | |||
| Shared.binding = activityPluginBinding | |||
| } | |||
| override fun onDetachedFromActivity() { | |||
| Shared.activity = null | |||
| activity = null | |||
| Shared.binding = null | |||
| } | |||
| @@ -34,10 +34,6 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v | |||
| Shared.binding!!.addRequestPermissionsResultListener(this) | |||
| } | |||
| if (Shared.registrar != null) { | |||
| Shared.registrar!!.addRequestPermissionsResultListener(this) | |||
| } | |||
| channel.setMethodCallHandler(this) | |||
| Shared.activity?.application?.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks { | |||
| override fun onActivityPaused(p0: Activity) { | |||
| @@ -306,14 +302,14 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v | |||
| permissions: Array<out String>?, | |||
| grantResults: IntArray): Boolean { | |||
| if(requestCode == Shared.CAMERA_REQUEST_ID + this.id) { | |||
| if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||
| return if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||
| permissionGranted = true | |||
| channel.invokeMethod("onPermissionSet", true) | |||
| return true | |||
| true | |||
| } else { | |||
| permissionGranted = false | |||
| channel.invokeMethod("onPermissionSet", false) | |||
| return false | |||
| false | |||
| } | |||
| } | |||
| return false | |||
| @@ -8,5 +8,4 @@ object Shared { | |||
| const val CAMERA_REQUEST_ID = 513469796 | |||
| var activity: Activity? = null | |||
| var binding: ActivityPluginBinding? = null | |||
| var registrar: PluginRegistry.Registrar? = null | |||
| } | |||
| @@ -0,0 +1 @@ | |||
| include: package:flutter_lints/flutter.yaml | |||
| @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' | |||
| apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" | |||
| android { | |||
| compileSdkVersion 30 | |||
| compileSdkVersion 31 | |||
| sourceSets { | |||
| main.java.srcDirs += 'src/main/kotlin' | |||
| @@ -36,7 +36,7 @@ android { | |||
| applicationId "net.touchcapture.qr.flutterqrexample" | |||
| // minSdkVersion is determined by Native View. | |||
| minSdkVersion 20 | |||
| targetSdkVersion 30 | |||
| targetSdkVersion 31 | |||
| versionCode flutterVersionCode.toInteger() | |||
| versionName flutterVersionName | |||
| testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |||
| @@ -56,7 +56,7 @@ flutter { | |||
| dependencies { | |||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |||
| testImplementation 'junit:junit:4.13.1' | |||
| testImplementation 'junit:junit:4.13.2' | |||
| androidTestImplementation 'com.android.support.test:runner:1.0.2' | |||
| androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | |||
| } | |||
| @@ -16,17 +16,13 @@ | |||
| android:label="flutter_qr_example" | |||
| android:icon="@mipmap/ic_launcher"> | |||
| <activity | |||
| android:name=".MainActivity" | |||
| android:name="io.flutter.embedding.android.FlutterActivity" | |||
| android:launchMode="singleTop" | |||
| android:theme="@style/LaunchTheme" | |||
| android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density" | |||
| android:hardwareAccelerated="true" | |||
| android:exported='true' | |||
| android:windowSoftInputMode="adjustResize"> | |||
| <!-- Specify that the launch screen should continue being displayed --> | |||
| <!-- until Flutter renders its first frame. --> | |||
| <meta-data | |||
| android:name="io.flutter.embedding.android.SplashScreenDrawable" | |||
| android:resource="@drawable/launch_background" /> | |||
| <!-- Theme to apply as soon as Flutter begins rendering frames --> | |||
| <meta-data | |||
| android:name="io.flutter.embedding.android.NormalTheme" | |||
| @@ -1,6 +0,0 @@ | |||
| package net.touchcapture.qr.flutterqrexample | |||
| import io.flutter.embedding.android.FlutterActivity | |||
| class MainActivity: FlutterActivity() { | |||
| } | |||
| @@ -1,12 +1,12 @@ | |||
| buildscript { | |||
| ext.kotlin_version = '1.5.10' | |||
| ext.kotlin_version = '1.5.31' | |||
| repositories { | |||
| google() | |||
| mavenCentral() | |||
| } | |||
| dependencies { | |||
| classpath 'com.android.tools.build:gradle:4.2.1' | |||
| classpath 'com.android.tools.build:gradle:7.0.2' | |||
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |||
| } | |||
| } | |||
| @@ -1,6 +1,6 @@ | |||
| #Thu Dec 10 21:49:57 CET 2020 | |||
| #Fri Oct 08 10:14:36 CEST 2021 | |||
| distributionBase=GRADLE_USER_HOME | |||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | |||
| distributionPath=wrapper/dists | |||
| zipStoreBase=GRADLE_USER_HOME | |||
| zipStorePath=wrapper/dists | |||
| distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip | |||
| zipStoreBase=GRADLE_USER_HOME | |||
| @@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| import 'package:qr_code_scanner/qr_code_scanner.dart'; | |||
| void main() => runApp(MaterialApp(home: MyHome())); | |||
| void main() => runApp(const MaterialApp(home: MyHome())); | |||
| class MyHome extends StatelessWidget { | |||
| const MyHome({Key? key}) : super(key: key); | |||
| @@ -13,15 +13,15 @@ class MyHome extends StatelessWidget { | |||
| @override | |||
| Widget build(BuildContext context) { | |||
| return Scaffold( | |||
| appBar: AppBar(title: Text('Flutter Demo Home Page')), | |||
| appBar: AppBar(title: const Text('Flutter Demo Home Page')), | |||
| body: Center( | |||
| child: ElevatedButton( | |||
| onPressed: () { | |||
| Navigator.of(context).push(MaterialPageRoute( | |||
| builder: (context) => QRViewExample(), | |||
| builder: (context) => const QRViewExample(), | |||
| )); | |||
| }, | |||
| child: Text('qrView'), | |||
| child: const Text('qrView'), | |||
| ), | |||
| ), | |||
| ); | |||
| @@ -29,6 +29,8 @@ class MyHome extends StatelessWidget { | |||
| } | |||
| class QRViewExample extends StatefulWidget { | |||
| const QRViewExample({Key? key}) : super(key: key); | |||
| @override | |||
| State<StatefulWidget> createState() => _QRViewExampleState(); | |||
| } | |||
| @@ -66,13 +68,13 @@ class _QRViewExampleState extends State<QRViewExample> { | |||
| Text( | |||
| 'Barcode Type: ${describeEnum(result!.format)} Data: ${result!.code}') | |||
| else | |||
| Text('Scan a code'), | |||
| const Text('Scan a code'), | |||
| Row( | |||
| mainAxisAlignment: MainAxisAlignment.center, | |||
| crossAxisAlignment: CrossAxisAlignment.center, | |||
| children: <Widget>[ | |||
| Container( | |||
| margin: EdgeInsets.all(8), | |||
| margin: const EdgeInsets.all(8), | |||
| child: ElevatedButton( | |||
| onPressed: () async { | |||
| await controller?.toggleFlash(); | |||
| @@ -86,7 +88,7 @@ class _QRViewExampleState extends State<QRViewExample> { | |||
| )), | |||
| ), | |||
| Container( | |||
| margin: EdgeInsets.all(8), | |||
| margin: const EdgeInsets.all(8), | |||
| child: ElevatedButton( | |||
| onPressed: () async { | |||
| await controller?.flipCamera(); | |||
| @@ -99,7 +101,7 @@ class _QRViewExampleState extends State<QRViewExample> { | |||
| return Text( | |||
| 'Camera facing ${describeEnum(snapshot.data!)}'); | |||
| } else { | |||
| return Text('loading'); | |||
| return const Text('loading'); | |||
| } | |||
| }, | |||
| )), | |||
| @@ -111,21 +113,23 @@ class _QRViewExampleState extends State<QRViewExample> { | |||
| crossAxisAlignment: CrossAxisAlignment.center, | |||
| children: <Widget>[ | |||
| Container( | |||
| margin: EdgeInsets.all(8), | |||
| margin: const EdgeInsets.all(8), | |||
| child: ElevatedButton( | |||
| onPressed: () async { | |||
| await controller?.pauseCamera(); | |||
| }, | |||
| child: Text('pause', style: TextStyle(fontSize: 20)), | |||
| child: const Text('pause', | |||
| style: TextStyle(fontSize: 20)), | |||
| ), | |||
| ), | |||
| Container( | |||
| margin: EdgeInsets.all(8), | |||
| margin: const EdgeInsets.all(8), | |||
| child: ElevatedButton( | |||
| onPressed: () async { | |||
| await controller?.resumeCamera(); | |||
| }, | |||
| child: Text('resume', style: TextStyle(fontSize: 20)), | |||
| child: const Text('resume', | |||
| style: TextStyle(fontSize: 20)), | |||
| ), | |||
| ) | |||
| ], | |||
| @@ -175,7 +179,7 @@ class _QRViewExampleState extends State<QRViewExample> { | |||
| log('${DateTime.now().toIso8601String()}_onPermissionSet $p'); | |||
| if (!p) { | |||
| ScaffoldMessenger.of(context).showSnackBar( | |||
| SnackBar(content: Text('no Permission')), | |||
| const SnackBar(content: Text('no Permission')), | |||
| ); | |||
| } | |||
| } | |||
| @@ -10,7 +10,7 @@ dependencies: | |||
| sdk: flutter | |||
| dev_dependencies: | |||
| pedantic: ^1.11.0 | |||
| flutter_lints: ^1.0.4 | |||
| flutter_test: | |||
| sdk: flutter | |||
| @@ -126,7 +126,7 @@ class _QRViewState extends State<QRView> { | |||
| onPlatformViewCreated: _onPlatformViewCreated, | |||
| creationParams: | |||
| _QrCameraSettings(cameraFacing: widget.cameraFacing).toMap(), | |||
| creationParamsCodec: StandardMessageCodec(), | |||
| creationParamsCodec: const StandardMessageCodec(), | |||
| ); | |||
| break; | |||
| case TargetPlatform.iOS: | |||
| @@ -135,7 +135,7 @@ class _QRViewState extends State<QRView> { | |||
| onPlatformViewCreated: _onPlatformViewCreated, | |||
| creationParams: | |||
| _QrCameraSettings(cameraFacing: widget.cameraFacing).toMap(), | |||
| creationParamsCodec: StandardMessageCodec(), | |||
| creationParamsCodec: const StandardMessageCodec(), | |||
| ); | |||
| break; | |||
| default: | |||
| @@ -327,7 +327,7 @@ class QRViewController { | |||
| {QrScannerOverlayShape? overlay}) async { | |||
| if (defaultTargetPlatform == TargetPlatform.iOS) { | |||
| // Add small delay to ensure the render box is loaded | |||
| await Future.delayed(Duration(milliseconds: 300)); | |||
| await Future.delayed(const Duration(milliseconds: 300)); | |||
| if (key.currentContext == null) return false; | |||
| final renderBox = key.currentContext!.findRenderObject() as RenderBox; | |||
| try { | |||
| @@ -1,3 +1,5 @@ | |||
| // ignore_for_file: avoid_web_libraries_in_flutter | |||
| import 'dart:async'; | |||
| import 'dart:core'; | |||
| import 'dart:html' as html; | |||
| @@ -59,11 +61,11 @@ class _WebQrViewState extends State<WebQrView> { | |||
| QRViewControllerWeb? _controller; | |||
| late Size _size = Size(0, 0); | |||
| late Size _size = const Size(0, 0); | |||
| Timer? timer; | |||
| String? code; | |||
| String? _errorMsg; | |||
| var video; | |||
| html.VideoElement video = html.VideoElement(); | |||
| String viewID = 'QRVIEW-' + DateTime.now().millisecondsSinceEpoch.toString(); | |||
| final StreamController<Barcode> _scanUpdateController = | |||
| @@ -78,13 +80,13 @@ class _WebQrViewState extends State<WebQrView> { | |||
| facing = widget.cameraFacing ?? CameraFacing.front; | |||
| video = html.VideoElement(); | |||
| // video = html.VideoElement(); | |||
| WebQrView.vidDiv.children = [video]; | |||
| // ignore: UNDEFINED_PREFIXED_NAME | |||
| ui.platformViewRegistry | |||
| .registerViewFactory(viewID, (int id) => WebQrView.vidDiv); | |||
| // giving JavaScipt some time to process the DOM changes | |||
| Timer(Duration(milliseconds: 500), () { | |||
| Timer(const Duration(milliseconds: 500), () { | |||
| start(); | |||
| }); | |||
| } | |||
| @@ -92,7 +94,8 @@ class _WebQrViewState extends State<WebQrView> { | |||
| Future start() async { | |||
| await _makeCall(); | |||
| _frameIntervall?.cancel(); | |||
| _frameIntervall = Timer.periodic(Duration(milliseconds: 200), (timer) { | |||
| _frameIntervall = | |||
| Timer.periodic(const Duration(milliseconds: 200), (timer) { | |||
| _captureFrame2(); | |||
| }); | |||
| } | |||
| @@ -202,7 +205,7 @@ class _WebQrViewState extends State<WebQrView> { | |||
| return Center(child: Text(_errorMsg!)); | |||
| } | |||
| if (_localStream == null) { | |||
| return Center(child: CircularProgressIndicator()); | |||
| return const Center(child: CircularProgressIndicator()); | |||
| } | |||
| return LayoutBuilder( | |||
| builder: (context, constraints) { | |||
| @@ -6,7 +6,7 @@ repository: https://github.com/juliuscanute/qr_code_scanner | |||
| environment: | |||
| sdk: '>=2.12.0 <3.0.0' | |||
| flutter: ">=1.10.0" | |||
| flutter: ">=1.12.0" | |||
| dependencies: | |||
| js: ^0.6.3 | |||
| @@ -16,7 +16,7 @@ dependencies: | |||
| sdk: flutter | |||
| dev_dependencies: | |||
| pedantic: ^1.11.0 | |||
| flutter_lints: ^1.0.4 | |||
| flutter: | |||
| plugin: | |||