├── .ci └── Dockerfile ├── .cirrus.yml ├── .gitignore ├── .idea ├── encodings.xml ├── libraries │ ├── Dart_SDK.xml │ ├── Flutter_Plugins.xml │ └── Flutter_for_Android.xml ├── misc.xml ├── modules.xml ├── runConfigurations │ └── example_lib_main_dart.xml ├── vcs.xml └── workspace.xml ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Screenshot_20190608-153849.jpg ├── android ├── .classpath ├── .gitignore ├── .project ├── build.gradle ├── gradle.properties ├── settings.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ ├── com │ └── google │ │ └── zxing │ │ └── client │ │ └── android │ │ └── camera │ │ ├── AutoFocusManager.java │ │ ├── CameraConfigurationManager.java │ │ ├── CameraManager.java │ │ └── open │ │ ├── CameraFacing.java │ │ ├── OpenCamera.java │ │ └── OpenCameraInterface.java │ └── me │ └── hetian │ └── flutter_qr_reader │ ├── FlutterQrReaderPlugin.java │ ├── QRCodeDecoder.java │ ├── factorys │ └── QrReaderFactory.java │ ├── readerView │ ├── Orientation.java │ ├── QRCodeReaderView.java │ ├── QRToViewPointTransformer.java │ ├── README.md │ └── SimpleLog.java │ └── views │ └── QrReaderView.java ├── assets ├── tool_flashlight_close.png ├── tool_flashlight_open.png ├── tool_img.png └── tool_qrcode.png ├── example ├── .gitignore ├── .metadata ├── README.md ├── android │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── me │ │ │ │ │ └── hetian │ │ │ │ │ └── flutter_qr_reader_example │ │ │ │ │ └── MainActivity.java │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── ios │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Podfile │ ├── Podfile.lock │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── Runner │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── main.m ├── lib │ ├── main.dart │ └── scanViewDemo.dart ├── pubspec.lock ├── pubspec.yaml └── test │ └── widget_test.dart ├── ezgif-3-7c8bfe5fd68a.gif ├── flutter_qr_reader.iml ├── ios ├── .gitignore ├── Assets │ └── .gitkeep ├── Classes │ ├── FlutterQrReaderPlugin.h │ ├── FlutterQrReaderPlugin.m │ ├── QrReaderViewController.h │ └── QrReaderViewController.m └── flutter_qr_reader.podspec ├── lib ├── flutter_qr_reader.dart └── qrcode_reader_view.dart ├── pubspec.lock ├── pubspec.yaml └── test └── flutter_qr_reader_test.dart /.ci/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cirrusci/flutter:stable 2 | 3 | RUN sudo apt-get update -y 4 | 5 | RUN sudo apt-get install -y --no-install-recommends gnupg 6 | 7 | # Add repo for gcloud sdk and install it 8 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | \ 9 | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list 10 | 11 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \ 12 | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - 13 | 14 | RUN sudo apt-get update && sudo apt-get install -y google-cloud-sdk && \ 15 | gcloud config set core/disable_usage_reporting true && \ 16 | gcloud config set component_manager/disable_update_check true 17 | 18 | RUN yes | sdkmanager \ 19 | "platforms;android-29" \ 20 | "build-tools;29.0.2" \ 21 | "extras;google;m2repository" \ 22 | "extras;android;m2repository" 23 | 24 | RUN yes | sdkmanager \ 25 | "platforms;android-28" \ 26 | "build-tools;28.0.3" \ 27 | "extras;google;m2repository" \ 28 | "extras;android;m2repository" 29 | 30 | RUN yes | sdkmanager --licenses 31 | -------------------------------------------------------------------------------- /.cirrus.yml: -------------------------------------------------------------------------------- 1 | task: 2 | container: 3 | dockerfile: .ci/Dockerfile 4 | cpu: 8 5 | memory: 16G 6 | pub_cache: 7 | folder: ~/.pub-cache 8 | setup_script: 9 | - flutter channel stable 10 | - flutter upgrade 11 | build_script: 12 | - cd example 13 | - flutter build apk 14 | test_script: flutter test 15 | 16 | task: 17 | osx_instance: 18 | image: mojave-flutter 19 | pub_cache: 20 | folder: ~/.pub-cache 21 | setup_script: 22 | - pod repo update 23 | - flutter channel stable 24 | - flutter upgrade 25 | create_simulator_script: 26 | - xcrun simctl list 27 | - xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-X com.apple.CoreSimulator.SimRuntime.iOS-12-2 | xargs xcrun simctl boot 28 | build_script: 29 | - cd example 30 | - flutter build ios --no-codesign 31 | test_script: flutter test 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | .idea/ 7 | 8 | build/ 9 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/libraries/Dart_SDK.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/libraries/Flutter_Plugins.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Flutter_for_Android.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations/example_lib_main_dart.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 19 | 20 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 41 | 42 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 1559875859613 63 | 68 | 69 | 70 | 71 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: b3b6d03737bd3f61209570e86f2b045c80f35c44 8 | channel: dev 9 | 10 | project_type: plugin 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.1 2 | 3 | ## 0.0.2 4 | 5 | 增加内置UI 6 | 7 | ## 0.0.3 8 | 9 | ## 0.0.4 10 | 11 | ## 0.0.5 12 | 13 | ## 1.0.0 14 | 15 | ## 1.0.0+1 16 | 17 | ## 1.0.1 18 | 19 | 修改扫码后的操作 20 | 21 | ## 1.0.2 22 | 23 | 降低zxing版本至3.3.3 24 | 25 | ## 1.0.3 26 | 27 | 解决scanBoxRatio无效问题 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 hetian9288 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_qr_reader 2 | 3 | QR code (scan code / picture) recognition (AndroidView/UiKitView) 4 | 5 | ## DEMO 6 | 7 | ![demo](https://github.com/hetian9288/flutter_qr_reader/blob/master/Screenshot_20190608-153849.jpg?raw=true) 8 | 9 | ![demo](https://github.com/hetian9288/flutter_qr_reader/blob/master/ezgif-3-7c8bfe5fd68a.gif?raw=true) 10 | 11 | ## Getting Started 12 | 13 | ``` dart 14 | import 'package:flutter_qr_reader/flutter_qr_reader.dart'; 15 | 16 | // 识别图片 17 | final String data = await FlutterQrReader.imgScan(File); 18 | 19 | // 嵌入视图 20 | QrReaderView( 21 | width: 320, 22 | height: 350, 23 | callback: (container) {}, 24 | ) 25 | // 打开手电筒 26 | ..setFlashlight 27 | // 开始扫码 28 | ..startCamera 29 | // 结束扫码 30 | ..stopCamera 31 | ``` 32 | 33 | ### For IOS 34 | Opt-in to the embedded views preview by adding a boolean property to the app's Info.plist file with the key io.flutter.embedded_views_preview and the value YES. 35 | 36 | io.flutter.embedded_views_preview 37 | YES 38 | 39 | And you will need provide the description of camera's permission to work properly, otherwise will crash your app. 40 | ``` 41 | NSCameraUsageDescription 42 | The porpuse explaining why you will use the camera 43 | ``` 44 | 45 | ## Built-in UI 46 | 47 | ``` dart 48 | Widget build(BuildContext context) { 49 | return new Scaffold( 50 | body: QrcodeReaderView(key: qrViewKey, onScan: onScan), 51 | ); 52 | } 53 | 54 | GlobalKey qrViewKey = GlobalKey(); 55 | 56 | Future onScan(String data) async { 57 | await showCupertinoDialog( 58 | context: context, 59 | builder: (context) { 60 | return CupertinoAlertDialog( 61 | title: Text("扫码结果"), 62 | content: Text(data), 63 | actions: [ 64 | CupertinoDialogAction( 65 | child: Text("确认"), 66 | onPressed: () => Navigator.pop(context), 67 | ) 68 | ], 69 | ); 70 | }, 71 | ); 72 | qrViewKey.currentState.startScan(); 73 | } 74 | ``` 75 | -------------------------------------------------------------------------------- /Screenshot_20190608-153849.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/Screenshot_20190608-153849.jpg -------------------------------------------------------------------------------- /android/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | flutter_qr_reader 4 | Project flutter_qr_reader created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | group 'me.hetian.flutter_qr_reader' 2 | version '1.0-SNAPSHOT' 3 | 4 | buildscript { 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.2.1' 12 | } 13 | } 14 | 15 | rootProject.allprojects { 16 | repositories { 17 | google() 18 | jcenter() 19 | } 20 | } 21 | 22 | apply plugin: 'com.android.library' 23 | 24 | android { 25 | compileSdkVersion 28 26 | 27 | defaultConfig { 28 | minSdkVersion 16 29 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 30 | } 31 | lintOptions { 32 | disable 'InvalidPackage' 33 | } 34 | } 35 | 36 | 37 | dependencies { 38 | implementation('com.google.zxing:core:3.3.3') 39 | } -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | 3 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'flutter_qr_reader' 2 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/src/main/java/com/google/zxing/client/android/camera/AutoFocusManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * -- Class modifications 17 | * 18 | * Copyright 2016 David Lázaro Esparcia. 19 | * 20 | * Licensed under the Apache License, Version 2.0 (the "License"); 21 | * you may not use this file except in compliance with the License. 22 | * You may obtain a copy of the License at 23 | * 24 | * http://www.apache.org/licenses/LICENSE-2.0 25 | * 26 | * Unless required by applicable law or agreed to in writing, software 27 | * distributed under the License is distributed on an "AS IS" BASIS, 28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | * See the License for the specific language governing permissions and 30 | * limitations under the License. 31 | */ 32 | 33 | package com.google.zxing.client.android.camera; 34 | 35 | import android.annotation.SuppressLint; 36 | import android.hardware.Camera; 37 | import android.os.AsyncTask; 38 | 39 | import java.util.ArrayList; 40 | import java.util.Collection; 41 | import java.util.concurrent.RejectedExecutionException; 42 | 43 | import me.hetian.flutter_qr_reader.readerView.SimpleLog; 44 | 45 | final class AutoFocusManager implements Camera.AutoFocusCallback { 46 | 47 | private static final String TAG = AutoFocusManager.class.getSimpleName(); 48 | 49 | protected static final long DEFAULT_AUTO_FOCUS_INTERVAL_MS = 5000L; 50 | private static final Collection FOCUS_MODES_CALLING_AF; 51 | private long autofocusIntervalMs = DEFAULT_AUTO_FOCUS_INTERVAL_MS; 52 | 53 | static { 54 | FOCUS_MODES_CALLING_AF = new ArrayList<>(2); 55 | FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_AUTO); 56 | FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_MACRO); 57 | } 58 | 59 | private boolean stopped; 60 | private boolean focusing; 61 | private final boolean useAutoFocus; 62 | private final Camera camera; 63 | private AsyncTask outstandingTask; 64 | 65 | AutoFocusManager(Camera camera) { 66 | this.camera = camera; 67 | String currentFocusMode = camera.getParameters().getFocusMode(); 68 | useAutoFocus = FOCUS_MODES_CALLING_AF.contains(currentFocusMode); 69 | SimpleLog.i(TAG, "Current focus mode '" 70 | + currentFocusMode 71 | + "'; use auto focus? " 72 | + useAutoFocus); 73 | start(); 74 | } 75 | 76 | @Override public synchronized void onAutoFocus(boolean success, Camera theCamera) { 77 | focusing = false; 78 | autoFocusAgainLater(); 79 | } 80 | 81 | public void setAutofocusInterval(long autofocusIntervalMs) { 82 | if (autofocusIntervalMs <= 0) { 83 | throw new IllegalArgumentException("AutoFocusInterval must be greater than 0."); 84 | } 85 | this.autofocusIntervalMs = autofocusIntervalMs; 86 | } 87 | 88 | @SuppressLint("NewApi") 89 | private synchronized void autoFocusAgainLater() { 90 | if (!stopped && outstandingTask == null) { 91 | AutoFocusTask newTask = new AutoFocusTask(); 92 | try { 93 | newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 94 | outstandingTask = newTask; 95 | } catch (RejectedExecutionException ree) { 96 | SimpleLog.w(TAG, "Could not request auto focus", ree); 97 | } 98 | } 99 | } 100 | 101 | synchronized void start() { 102 | if (useAutoFocus) { 103 | outstandingTask = null; 104 | if (!stopped && !focusing) { 105 | try { 106 | camera.autoFocus(this); 107 | focusing = true; 108 | } catch (RuntimeException re) { 109 | // Have heard RuntimeException reported in Android 4.0.x+; continue? 110 | SimpleLog.w(TAG, "Unexpected exception while focusing", re); 111 | // Try again later to keep cycle going 112 | autoFocusAgainLater(); 113 | } 114 | } 115 | } 116 | } 117 | 118 | private synchronized void cancelOutstandingTask() { 119 | if (outstandingTask != null) { 120 | if (outstandingTask.getStatus() != AsyncTask.Status.FINISHED) { 121 | outstandingTask.cancel(true); 122 | } 123 | outstandingTask = null; 124 | } 125 | } 126 | 127 | synchronized void stop() { 128 | stopped = true; 129 | if (useAutoFocus) { 130 | cancelOutstandingTask(); 131 | // Doesn't hurt to call this even if not focusing 132 | try { 133 | camera.cancelAutoFocus(); 134 | } catch (RuntimeException re) { 135 | // Have heard RuntimeException reported in Android 4.0.x+; continue? 136 | SimpleLog.w(TAG, "Unexpected exception while cancelling focusing", re); 137 | } 138 | } 139 | } 140 | 141 | private final class AutoFocusTask extends AsyncTask { 142 | @Override protected Object doInBackground(Object... voids) { 143 | try { 144 | Thread.sleep(autofocusIntervalMs); 145 | } catch (InterruptedException e) { 146 | // continue 147 | } 148 | start(); 149 | return null; 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /android/src/main/java/com/google/zxing/client/android/camera/CameraConfigurationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.zxing.client.android.camera; 18 | 19 | import android.content.Context; 20 | import android.graphics.Point; 21 | import android.hardware.Camera; 22 | import android.util.Log; 23 | import android.view.Display; 24 | import android.view.Surface; 25 | import android.view.WindowManager; 26 | 27 | 28 | import java.util.ArrayList; 29 | import java.util.Arrays; 30 | import java.util.Collection; 31 | import java.util.Collections; 32 | import java.util.Comparator; 33 | import java.util.List; 34 | 35 | import me.hetian.flutter_qr_reader.readerView.SimpleLog; 36 | import com.google.zxing.client.android.camera.open.CameraFacing; 37 | import com.google.zxing.client.android.camera.open.OpenCamera; 38 | 39 | /** 40 | * A class which deals with reading, parsing, and setting the google.zxing.client.android.android.com.google.zxing.client.android.camera parameters which are used to 41 | * configure the google.zxing.client.android.android.com.google.zxing.client.android.camera hardware. 42 | */ 43 | final class CameraConfigurationManager { 44 | 45 | private static final String TAG = "CameraConfiguration"; 46 | 47 | // This is bigger than the size of a small screen, which is still supported. The routine 48 | // below will still select the default (presumably 320x240) size for these. This prevents 49 | // accidental selection of very low resolution on some devices. 50 | private static final int MIN_PREVIEW_PIXELS = 470 * 320; // normal screen 51 | private static final int MAX_PREVIEW_PIXELS = 1280 * 720; 52 | private static final float MAX_EXPOSURE_COMPENSATION = 1.5f; 53 | private static final float MIN_EXPOSURE_COMPENSATION = 0.0f; 54 | private final Context context; 55 | 56 | private Point resolution; 57 | private Point cameraResolution; 58 | private Point bestPreviewSize; 59 | private Point previewSizeOnScreen; 60 | private int cwRotationFromDisplayToCamera; 61 | private int cwNeededRotation; 62 | 63 | CameraConfigurationManager(Context context) { 64 | this.context = context; 65 | } 66 | 67 | void initFromCameraParameters(OpenCamera camera, int width, int height) { 68 | Camera.Parameters parameters = camera.getCamera().getParameters(); 69 | WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 70 | Display display = manager.getDefaultDisplay(); 71 | 72 | int displayRotation = display.getRotation(); 73 | int cwRotationFromNaturalToDisplay; 74 | switch (displayRotation) { 75 | case Surface.ROTATION_0: 76 | cwRotationFromNaturalToDisplay = 0; 77 | break; 78 | case Surface.ROTATION_90: 79 | cwRotationFromNaturalToDisplay = 90; 80 | break; 81 | case Surface.ROTATION_180: 82 | cwRotationFromNaturalToDisplay = 180; 83 | break; 84 | case Surface.ROTATION_270: 85 | cwRotationFromNaturalToDisplay = 270; 86 | break; 87 | default: 88 | // Have seen this return incorrect values like -90 89 | if (displayRotation % 90 == 0) { 90 | cwRotationFromNaturalToDisplay = (360 + displayRotation) % 360; 91 | } else { 92 | throw new IllegalArgumentException("Bad rotation: " + displayRotation); 93 | } 94 | } 95 | SimpleLog.i(TAG, "Display at: " + cwRotationFromNaturalToDisplay); 96 | 97 | int cwRotationFromNaturalToCamera = camera.getOrientation(); 98 | SimpleLog.i(TAG, "Camera at: " + cwRotationFromNaturalToCamera); 99 | 100 | // Still not 100% sure about this. But acts like we need to flip this: 101 | if (camera.getFacing() == CameraFacing.FRONT) { 102 | cwRotationFromNaturalToCamera = (360 - cwRotationFromNaturalToCamera) % 360; 103 | SimpleLog.i(TAG, "Front google.zxing.client.android.android.com.google.zxing.client.android.camera overriden to: " + cwRotationFromNaturalToCamera); 104 | } 105 | 106 | cwRotationFromDisplayToCamera = 107 | (360 + cwRotationFromNaturalToCamera - cwRotationFromNaturalToDisplay) % 360; 108 | SimpleLog.i(TAG, "Final display orientation: " + cwRotationFromDisplayToCamera); 109 | if (camera.getFacing() == CameraFacing.FRONT) { 110 | SimpleLog.i(TAG, "Compensating rotation for front google.zxing.client.android.android.com.google.zxing.client.android.camera"); 111 | cwNeededRotation = (360 - cwRotationFromDisplayToCamera) % 360; 112 | } else { 113 | cwNeededRotation = cwRotationFromDisplayToCamera; 114 | } 115 | SimpleLog.i(TAG, "Clockwise rotation from display to google.zxing.client.android.android.com.google.zxing.client.android.camera: " + cwNeededRotation); 116 | 117 | resolution = new Point(width, height); 118 | SimpleLog.i(TAG, "Screen resolution in current orientation: " + resolution); 119 | cameraResolution = findBestPreviewSizeValue(parameters, resolution); 120 | SimpleLog.i(TAG, "Camera resolution: " + cameraResolution); 121 | bestPreviewSize = findBestPreviewSizeValue(parameters, resolution); 122 | SimpleLog.i(TAG, "Best available preview size: " + bestPreviewSize); 123 | 124 | boolean isScreenPortrait = resolution.x < resolution.y; 125 | boolean isPreviewSizePortrait = bestPreviewSize.x < bestPreviewSize.y; 126 | 127 | if (isScreenPortrait == isPreviewSizePortrait) { 128 | previewSizeOnScreen = bestPreviewSize; 129 | } else { 130 | previewSizeOnScreen = new Point(bestPreviewSize.y, bestPreviewSize.x); 131 | } 132 | SimpleLog.i(TAG, "Preview size on screen: " + previewSizeOnScreen); 133 | } 134 | 135 | void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) { 136 | 137 | Camera theCamera = camera.getCamera(); 138 | Camera.Parameters parameters = theCamera.getParameters(); 139 | 140 | if (parameters == null) { 141 | SimpleLog.w(TAG, 142 | "Device error: no google.zxing.client.android.android.com.google.zxing.client.android.camera parameters are available. Proceeding without configuration."); 143 | return; 144 | } 145 | 146 | SimpleLog.i(TAG, "Initial google.zxing.client.android.android.com.google.zxing.client.android.camera parameters: " + parameters.flatten()); 147 | 148 | if (safeMode) { 149 | SimpleLog.w(TAG, "In google.zxing.client.android.android.com.google.zxing.client.android.camera config safe mode -- most settings will not be honored"); 150 | } 151 | 152 | // Maybe selected auto-focus but not available, so fall through here: 153 | String focusMode = null; 154 | if (!safeMode) { 155 | List supportedFocusModes = parameters.getSupportedFocusModes(); 156 | focusMode = 157 | findSettableValue("focus mode", 158 | supportedFocusModes, 159 | Camera.Parameters.FOCUS_MODE_AUTO); 160 | } 161 | if (focusMode != null) { 162 | parameters.setFocusMode(focusMode); 163 | } 164 | 165 | parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y); 166 | 167 | theCamera.setParameters(parameters); 168 | 169 | theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera); 170 | 171 | Camera.Parameters afterParameters = theCamera.getParameters(); 172 | Camera.Size afterSize = afterParameters.getPreviewSize(); 173 | if (afterSize != null && (bestPreviewSize.x != afterSize.width 174 | || bestPreviewSize.y != afterSize.height)) { 175 | SimpleLog.w(TAG, 176 | "Camera said it supported preview size " 177 | + bestPreviewSize.x 178 | + 'x' 179 | + bestPreviewSize.y 180 | + ", but after setting it, preview size is " 181 | + afterSize.width 182 | + 'x' 183 | + afterSize.height); 184 | bestPreviewSize.x = afterSize.width; 185 | bestPreviewSize.y = afterSize.height; 186 | } 187 | } 188 | 189 | Point getCameraResolution() { 190 | return cameraResolution; 191 | } 192 | 193 | Point getScreenResolution() { 194 | return resolution; 195 | } 196 | 197 | // All references to Torch are removed from here, methods, variables... 198 | 199 | public Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { 200 | 201 | List rawSupportedSizes = parameters.getSupportedPreviewSizes(); 202 | if (rawSupportedSizes == null) { 203 | SimpleLog.w(TAG, "Device returned no supported preview sizes; using default"); 204 | Camera.Size defaultSize = parameters.getPreviewSize(); 205 | return new Point(defaultSize.width, defaultSize.height); 206 | } 207 | 208 | // Sort by size, descending 209 | List supportedPreviewSizes = new ArrayList(rawSupportedSizes); 210 | Collections.sort(supportedPreviewSizes, new Comparator() { 211 | @Override public int compare(Camera.Size a, Camera.Size b) { 212 | int aPixels = a.height * a.width; 213 | int bPixels = b.height * b.width; 214 | if (bPixels < aPixels) { 215 | return -1; 216 | } 217 | if (bPixels > aPixels) { 218 | return 1; 219 | } 220 | return 0; 221 | } 222 | }); 223 | 224 | if (Log.isLoggable(TAG, Log.INFO)) { 225 | StringBuilder previewSizesString = new StringBuilder(); 226 | for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { 227 | previewSizesString.append(supportedPreviewSize.width) 228 | .append('x') 229 | .append(supportedPreviewSize.height) 230 | .append(' '); 231 | } 232 | SimpleLog.i(TAG, "Supported preview sizes: " + previewSizesString); 233 | } 234 | 235 | Point bestSize = null; 236 | float screenAspectRatio = (float) screenResolution.x / (float) screenResolution.y; 237 | 238 | float diff = Float.POSITIVE_INFINITY; 239 | for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { 240 | int realWidth = supportedPreviewSize.width; 241 | int realHeight = supportedPreviewSize.height; 242 | int pixels = realWidth * realHeight; 243 | if (pixels < MIN_PREVIEW_PIXELS || pixels > MAX_PREVIEW_PIXELS) { 244 | continue; 245 | } 246 | 247 | // This code is modified since We're using portrait mode 248 | boolean isCandidateLandscape = realWidth > realHeight; 249 | int maybeFlippedWidth = isCandidateLandscape ? realHeight : realWidth; 250 | int maybeFlippedHeight = isCandidateLandscape ? realWidth : realHeight; 251 | 252 | if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { 253 | Point exactPoint = new Point(realWidth, realHeight); 254 | SimpleLog.i(TAG, "Found preview size exactly matching screen size: " + exactPoint); 255 | return exactPoint; 256 | } 257 | float aspectRatio = (float) maybeFlippedWidth / (float) maybeFlippedHeight; 258 | float newDiff = Math.abs(aspectRatio - screenAspectRatio); 259 | if (newDiff < diff) { 260 | bestSize = new Point(realWidth, realHeight); 261 | diff = newDiff; 262 | } 263 | } 264 | 265 | if (bestSize == null) { 266 | Camera.Size defaultSize = parameters.getPreviewSize(); 267 | bestSize = new Point(defaultSize.width, defaultSize.height); 268 | SimpleLog.i(TAG, "No suitable preview sizes, using default: " + bestSize); 269 | } 270 | 271 | SimpleLog.i(TAG, "Found best approximate preview size: " + bestSize); 272 | return bestSize; 273 | } 274 | 275 | private static String findSettableValue(String name, 276 | Collection supportedValues, 277 | String... desiredValues) { 278 | SimpleLog.i(TAG, "Requesting " + name + " value from among: " + Arrays.toString(desiredValues)); 279 | SimpleLog.i(TAG, "Supported " + name + " values: " + supportedValues); 280 | if (supportedValues != null) { 281 | for (String desiredValue : desiredValues) { 282 | if (supportedValues.contains(desiredValue)) { 283 | SimpleLog.i(TAG, "Can set " + name + " to: " + desiredValue); 284 | return desiredValue; 285 | } 286 | } 287 | } 288 | SimpleLog.i(TAG, "No supported values match"); 289 | return null; 290 | } 291 | 292 | boolean getTorchState(Camera camera) { 293 | if (camera != null) { 294 | Camera.Parameters parameters = camera.getParameters(); 295 | if (parameters != null) { 296 | String flashMode = camera.getParameters().getFlashMode(); 297 | return flashMode != null && (Camera.Parameters.FLASH_MODE_ON.equals(flashMode) 298 | || Camera.Parameters.FLASH_MODE_TORCH.equals(flashMode)); 299 | } 300 | } 301 | return false; 302 | } 303 | 304 | void setTorchEnabled(Camera camera, boolean enabled) { 305 | Camera.Parameters parameters = camera.getParameters(); 306 | setTorchEnabled(parameters, enabled, false); 307 | camera.setParameters(parameters); 308 | } 309 | 310 | void setTorchEnabled(Camera.Parameters parameters, boolean enabled, boolean safeMode) { 311 | setTorchEnabled(parameters, enabled); 312 | 313 | if (!safeMode) { 314 | setBestExposure(parameters, enabled); 315 | } 316 | } 317 | 318 | public static void setTorchEnabled(Camera.Parameters parameters, 319 | boolean enabled) { 320 | List supportedFlashModes = parameters.getSupportedFlashModes(); 321 | String flashMode; 322 | if (enabled) { 323 | flashMode = findSettableValue("flash mode", 324 | supportedFlashModes, 325 | Camera.Parameters.FLASH_MODE_TORCH, 326 | Camera.Parameters.FLASH_MODE_ON); 327 | } else { 328 | flashMode = findSettableValue("flash mode", 329 | supportedFlashModes, 330 | Camera.Parameters.FLASH_MODE_OFF); 331 | } 332 | if (flashMode != null) { 333 | if (flashMode.equals(parameters.getFlashMode())) { 334 | SimpleLog.i(TAG, "Flash mode already set to " + flashMode); 335 | } else { 336 | SimpleLog.i(TAG, "Setting flash mode to " + flashMode); 337 | parameters.setFlashMode(flashMode); 338 | } 339 | } 340 | } 341 | 342 | public static void setBestExposure(Camera.Parameters parameters, 343 | boolean lightOn) { 344 | 345 | int minExposure = parameters.getMinExposureCompensation(); 346 | int maxExposure = parameters.getMaxExposureCompensation(); 347 | float step = parameters.getExposureCompensationStep(); 348 | if ((minExposure != 0 || maxExposure != 0) && step > 0.0f) { 349 | // Set low when light is on 350 | float targetCompensation = lightOn ? MIN_EXPOSURE_COMPENSATION : MAX_EXPOSURE_COMPENSATION; 351 | int compensationSteps = Math.round(targetCompensation / step); 352 | float actualCompensation = step * compensationSteps; 353 | // Clamp value: 354 | compensationSteps = Math.max(Math.min(compensationSteps, maxExposure), minExposure); 355 | if (parameters.getExposureCompensation() == compensationSteps) { 356 | SimpleLog.i(TAG, "Exposure compensation already set to " + compensationSteps + " / " 357 | + actualCompensation); 358 | } else { 359 | SimpleLog.i(TAG, 360 | "Setting exposure compensation to " + compensationSteps + " / " + actualCompensation); 361 | parameters.setExposureCompensation(compensationSteps); 362 | } 363 | } else { 364 | SimpleLog.i(TAG, "Camera does not support exposure compensation"); 365 | } 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /android/src/main/java/com/google/zxing/client/android/camera/CameraManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.zxing.client.android.camera; 18 | 19 | import android.content.Context; 20 | import android.graphics.Point; 21 | import android.hardware.Camera; 22 | import android.view.SurfaceHolder; 23 | 24 | import com.google.zxing.PlanarYUVLuminanceSource; 25 | 26 | import java.io.IOException; 27 | 28 | import me.hetian.flutter_qr_reader.readerView.SimpleLog; 29 | import com.google.zxing.client.android.camera.open.OpenCamera; 30 | import com.google.zxing.client.android.camera.open.OpenCameraInterface; 31 | 32 | /** 33 | * This object wraps the Camera service object and expects to be the only one talking to it. The 34 | * implementation encapsulates the steps needed to take preview-sized images, which are used for 35 | * both preview and decoding. 36 | * 37 | * @author dswitkin@google.com (Daniel Switkin) 38 | */ 39 | public final class CameraManager { 40 | 41 | private static final String TAG = CameraManager.class.getSimpleName(); 42 | 43 | private final Context context; 44 | private final CameraConfigurationManager configManager; 45 | private OpenCamera openCamera; 46 | private AutoFocusManager autoFocusManager; 47 | private boolean initialized; 48 | private boolean previewing; 49 | private Camera.PreviewCallback previewCallback; 50 | private int displayOrientation = 0; 51 | 52 | // PreviewCallback references are also removed from original ZXING authors work, 53 | // since we're using our own interface. 54 | // FramingRects references are also removed from original ZXING authors work, 55 | // since We're using all view size while detecting QR-Codes. 56 | private int requestedCameraId = OpenCameraInterface.NO_REQUESTED_CAMERA; 57 | private long autofocusIntervalInMs = AutoFocusManager.DEFAULT_AUTO_FOCUS_INTERVAL_MS; 58 | 59 | public CameraManager(Context context) { 60 | this.context = context; 61 | this.configManager = new CameraConfigurationManager(context); 62 | } 63 | 64 | public void setPreviewCallback(Camera.PreviewCallback previewCallback) { 65 | this.previewCallback = previewCallback; 66 | 67 | if (isOpen()) { 68 | openCamera.getCamera().setPreviewCallback(previewCallback); 69 | } 70 | } 71 | 72 | public void setDisplayOrientation(int degrees) { 73 | this.displayOrientation = degrees; 74 | 75 | if (isOpen()) { 76 | openCamera.getCamera().setDisplayOrientation(degrees); 77 | } 78 | } 79 | 80 | public void setAutofocusInterval(long autofocusIntervalInMs) { 81 | this.autofocusIntervalInMs = autofocusIntervalInMs; 82 | if (autoFocusManager != null) { 83 | autoFocusManager.setAutofocusInterval(autofocusIntervalInMs); 84 | } 85 | } 86 | 87 | public void forceAutoFocus() { 88 | if (autoFocusManager != null) { 89 | autoFocusManager.start(); 90 | } 91 | } 92 | 93 | public Point getPreviewSize() { 94 | return configManager.getCameraResolution(); 95 | } 96 | 97 | /** 98 | * Opens the google.zxing.client.android.android.com.google.zxing.client.android.camera driver and initializes the hardware parameters. 99 | * 100 | * @param holder The surface object which the google.zxing.client.android.android.com.google.zxing.client.android.camera will draw preview frames into. 101 | * @param height @throws IOException Indicates the google.zxing.client.android.android.com.google.zxing.client.android.camera driver failed to open. 102 | */ 103 | public synchronized void openDriver(SurfaceHolder holder, int width, int height) 104 | throws IOException { 105 | OpenCamera theCamera = openCamera; 106 | if (!isOpen()) { 107 | theCamera = OpenCameraInterface.open(requestedCameraId); 108 | if (theCamera == null || theCamera.getCamera() == null) { 109 | throw new IOException("Camera.open() failed to return object from driver"); 110 | } 111 | openCamera = theCamera; 112 | } 113 | theCamera.getCamera().setPreviewDisplay(holder); 114 | theCamera.getCamera().setPreviewCallback(previewCallback); 115 | theCamera.getCamera().setDisplayOrientation(displayOrientation); 116 | 117 | if (!initialized) { 118 | initialized = true; 119 | configManager.initFromCameraParameters(theCamera, width, height); 120 | } 121 | 122 | Camera cameraObject = theCamera.getCamera(); 123 | Camera.Parameters parameters = cameraObject.getParameters(); 124 | String parametersFlattened = 125 | parameters == null ? null : parameters.flatten(); // Save these, temporarily 126 | try { 127 | configManager.setDesiredCameraParameters(theCamera, false); 128 | } catch (RuntimeException re) { 129 | // Driver failed 130 | SimpleLog.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters"); 131 | SimpleLog.i(TAG, "Resetting to saved google.zxing.client.android.android.com.google.zxing.client.android.camera params: " + parametersFlattened); 132 | // Reset: 133 | if (parametersFlattened != null) { 134 | parameters = cameraObject.getParameters(); 135 | parameters.unflatten(parametersFlattened); 136 | try { 137 | cameraObject.setParameters(parameters); 138 | configManager.setDesiredCameraParameters(theCamera, true); 139 | } catch (RuntimeException re2) { 140 | // Well, darn. Give up 141 | SimpleLog.w(TAG, "Camera rejected even safe-mode parameters! No configuration"); 142 | } 143 | } 144 | } 145 | cameraObject.setPreviewDisplay(holder); 146 | } 147 | 148 | /** 149 | * Allows third party apps to specify the google.zxing.client.android.android.com.google.zxing.client.android.camera ID, rather than determine 150 | * it automatically based on available cameras and their orientation. 151 | * 152 | * @param cameraId google.zxing.client.android.android.com.google.zxing.client.android.camera ID of the google.zxing.client.android.android.com.google.zxing.client.android.camera to use. A negative value means "no preference". 153 | */ 154 | public synchronized void setPreviewCameraId(int cameraId) { 155 | requestedCameraId = cameraId; 156 | } 157 | 158 | public int getPreviewCameraId() { 159 | return requestedCameraId; 160 | } 161 | 162 | /** 163 | * @param enabled if {@code true}, light should be turned on if currently off. And vice versa. 164 | */ 165 | public synchronized void setTorchEnabled(boolean enabled) { 166 | OpenCamera theCamera = openCamera; 167 | if (theCamera != null && enabled != configManager.getTorchState(theCamera.getCamera())) { 168 | boolean wasAutoFocusManager = autoFocusManager != null; 169 | if (wasAutoFocusManager) { 170 | autoFocusManager.stop(); 171 | autoFocusManager = null; 172 | } 173 | configManager.setTorchEnabled(theCamera.getCamera(), enabled); 174 | if (wasAutoFocusManager) { 175 | autoFocusManager = new AutoFocusManager(theCamera.getCamera()); 176 | autoFocusManager.start(); 177 | } 178 | } 179 | } 180 | 181 | public synchronized boolean isOpen() { 182 | return openCamera != null && openCamera.getCamera() != null; 183 | } 184 | 185 | /** 186 | * Closes the google.zxing.client.android.android.com.google.zxing.client.android.camera driver if still in use. 187 | */ 188 | public synchronized void closeDriver() { 189 | if (isOpen()) { 190 | openCamera.getCamera().release(); 191 | openCamera = null; 192 | // Make sure to clear these each time we close the google.zxing.client.android.android.com.google.zxing.client.android.camera, so that any scanning rect 193 | // requested by intent is forgotten. 194 | // framingRect = null; 195 | // framingRectInPreview = null; 196 | } 197 | } 198 | 199 | /** 200 | * Asks the google.zxing.client.android.android.com.google.zxing.client.android.camera hardware to begin drawing preview frames to the screen. 201 | */ 202 | public synchronized void startPreview() { 203 | OpenCamera theCamera = openCamera; 204 | if (theCamera != null && !previewing) { 205 | theCamera.getCamera().startPreview(); 206 | previewing = true; 207 | autoFocusManager = new AutoFocusManager(theCamera.getCamera()); 208 | autoFocusManager.setAutofocusInterval(autofocusIntervalInMs); 209 | } 210 | } 211 | 212 | /** 213 | * Tells the google.zxing.client.android.android.com.google.zxing.client.android.camera to stop drawing preview frames. 214 | */ 215 | public synchronized void stopPreview() { 216 | if (autoFocusManager != null) { 217 | autoFocusManager.stop(); 218 | autoFocusManager = null; 219 | } 220 | if (openCamera != null && previewing) { 221 | openCamera.getCamera().stopPreview(); 222 | previewing = false; 223 | } 224 | } 225 | 226 | /** 227 | * A factory method to build the appropriate LuminanceSource object based on the format 228 | * of the preview buffers, as described by Camera.Parameters. 229 | * 230 | * @param data A preview frame. 231 | * @param width The width of the image. 232 | * @param height The height of the image. 233 | * @return A PlanarYUVLuminanceSource instance. 234 | */ 235 | public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) { 236 | return new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false); 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /android/src/main/java/com/google/zxing/client/android/camera/open/CameraFacing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.zxing.client.android.camera.open; 17 | 18 | public enum CameraFacing { 19 | 20 | BACK, // must be value 0! 21 | FRONT, // must be value 1! 22 | 23 | } -------------------------------------------------------------------------------- /android/src/main/java/com/google/zxing/client/android/camera/open/OpenCamera.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.zxing.client.android.camera.open; 17 | 18 | import android.hardware.Camera; 19 | 20 | 21 | public final class OpenCamera { 22 | 23 | private final int index; 24 | private final Camera camera; 25 | private final CameraFacing facing; 26 | private final int orientation; 27 | 28 | public OpenCamera(int index, Camera camera, CameraFacing facing, int orientation) { 29 | this.index = index; 30 | this.camera = camera; 31 | this.facing = facing; 32 | this.orientation = orientation; 33 | } 34 | 35 | public Camera getCamera() { 36 | return camera; 37 | } 38 | 39 | public CameraFacing getFacing() { 40 | return facing; 41 | } 42 | 43 | public int getOrientation() { 44 | return orientation; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "Camera #" + index + " : " + facing + ',' + orientation; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /android/src/main/java/com/google/zxing/client/android/camera/open/OpenCameraInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.zxing.client.android.camera.open; 18 | 19 | import android.hardware.Camera; 20 | 21 | import me.hetian.flutter_qr_reader.readerView.SimpleLog; 22 | 23 | 24 | /** 25 | * Abstraction over the {@link Camera} API that helps open them and return their metadata. 26 | */ 27 | public final class OpenCameraInterface { 28 | 29 | private static final String TAG = OpenCameraInterface.class.getName(); 30 | 31 | private OpenCameraInterface() { 32 | } 33 | 34 | /** For {@link #open(int)}, means no preference for which google.zxing.client.android.android.com.google.zxing.client.android.camera to open. */ 35 | public static final int NO_REQUESTED_CAMERA = -1; 36 | 37 | /** 38 | * Opens the requested google.zxing.client.android.android.com.google.zxing.client.android.camera with {@link Camera#open(int)}, if one exists. 39 | * 40 | * @param cameraId google.zxing.client.android.android.com.google.zxing.client.android.camera ID of the google.zxing.client.android.android.com.google.zxing.client.android.camera to use. A negative value 41 | * or {@link #NO_REQUESTED_CAMERA} means "no preference", in which case a rear-facing 42 | * google.zxing.client.android.android.com.google.zxing.client.android.camera is returned if possible or else any google.zxing.client.android.android.com.google.zxing.client.android.camera 43 | * @return handle to {@link com.google.zxing.client.android.camera.open.OpenCamera} that was opened 44 | */ 45 | public static OpenCamera open(int cameraId) { 46 | 47 | int numCameras = Camera.getNumberOfCameras(); 48 | if (numCameras == 0) { 49 | SimpleLog.w(TAG, "No cameras!"); 50 | return null; 51 | } 52 | 53 | boolean explicitRequest = cameraId >= 0; 54 | 55 | Camera.CameraInfo selectedCameraInfo = null; 56 | int index; 57 | if (explicitRequest) { 58 | index = cameraId; 59 | selectedCameraInfo = new Camera.CameraInfo(); 60 | Camera.getCameraInfo(index, selectedCameraInfo); 61 | } else { 62 | index = 0; 63 | while (index < numCameras) { 64 | Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); 65 | Camera.getCameraInfo(index, cameraInfo); 66 | com.google.zxing.client.android.camera.open.CameraFacing reportedFacing = com.google.zxing.client.android.camera.open.CameraFacing.values()[cameraInfo.facing]; 67 | if (reportedFacing == com.google.zxing.client.android.camera.open.CameraFacing.BACK) { 68 | selectedCameraInfo = cameraInfo; 69 | break; 70 | } 71 | index++; 72 | } 73 | } 74 | 75 | Camera camera; 76 | if (index < numCameras) { 77 | SimpleLog.i(TAG, "Opening google.zxing.client.android.android.com.google.zxing.client.android.camera #" + index); 78 | camera = Camera.open(index); 79 | } else { 80 | if (explicitRequest) { 81 | SimpleLog.w(TAG, "Requested google.zxing.client.android.android.com.google.zxing.client.android.camera does not exist: " + cameraId); 82 | camera = null; 83 | } else { 84 | SimpleLog.i(TAG, "No google.zxing.client.android.android.com.google.zxing.client.android.camera facing " + com.google.zxing.client.android.camera.open.CameraFacing.BACK + "; returning google.zxing.client.android.android.com.google.zxing.client.android.camera #0"); 85 | camera = Camera.open(0); 86 | selectedCameraInfo = new Camera.CameraInfo(); 87 | Camera.getCameraInfo(0, selectedCameraInfo); 88 | } 89 | } 90 | 91 | if (camera == null) { 92 | return null; 93 | } 94 | return new OpenCamera(index, 95 | camera, 96 | CameraFacing.values()[selectedCameraInfo.facing], 97 | selectedCameraInfo.orientation); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/FlutterQrReaderPlugin.java: -------------------------------------------------------------------------------- 1 | package me.hetian.flutter_qr_reader; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.os.AsyncTask; 5 | 6 | import java.io.File; 7 | 8 | import io.flutter.plugin.common.MethodCall; 9 | import io.flutter.plugin.common.MethodChannel; 10 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler; 11 | import io.flutter.plugin.common.MethodChannel.Result; 12 | import io.flutter.plugin.common.PluginRegistry.Registrar; 13 | import me.hetian.flutter_qr_reader.factorys.QrReaderFactory; 14 | 15 | 16 | /** FlutterQrReaderPlugin */ 17 | public class FlutterQrReaderPlugin implements MethodCallHandler { 18 | 19 | // private static final int REQUEST_CODE_CAMERA_PERMISSION = 3777; 20 | private static final String CHANNEL_NAME = "me.hetian.flutter_qr_reader"; 21 | private static final String CHANNEL_VIEW_NAME = "me.hetian.flutter_qr_reader.reader_view"; 22 | 23 | 24 | private Registrar registrar; 25 | 26 | FlutterQrReaderPlugin(Registrar registrar) { 27 | this.registrar = registrar; 28 | } 29 | 30 | // private interface PermissionsResult { 31 | // void onSuccess(); 32 | // void onError(); 33 | // } 34 | 35 | /** Plugin registration. */ 36 | public static void registerWith(Registrar registrar) { 37 | final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME); 38 | registrar.platformViewRegistry().registerViewFactory(CHANNEL_VIEW_NAME, new QrReaderFactory(registrar)); 39 | final FlutterQrReaderPlugin instance = new FlutterQrReaderPlugin(registrar); 40 | channel.setMethodCallHandler(instance); 41 | } 42 | 43 | @Override 44 | public void onMethodCall(MethodCall call, Result result) { 45 | if (call.method.equals("imgQrCode")) { 46 | imgQrCode(call, result); 47 | } else { 48 | result.notImplemented(); 49 | } 50 | } 51 | 52 | @SuppressLint("StaticFieldLeak") 53 | void imgQrCode(MethodCall call, final Result result) { 54 | final String filePath = call.argument("file"); 55 | if (filePath == null) { 56 | result.error("Not found data", null, null); 57 | return; 58 | } 59 | File file = new File(filePath); 60 | if (!file.exists()) { 61 | result.error("File not found", null, null); 62 | } 63 | 64 | new AsyncTask() { 65 | @Override 66 | protected String doInBackground(String... params) { 67 | // 解析二维码/条码 68 | return QRCodeDecoder.syncDecodeQRCode(filePath); 69 | } 70 | @Override 71 | protected void onPostExecute(String s) { 72 | super.onPostExecute(s); 73 | if(null == s){ 74 | result.error("not data", null, null); 75 | }else { 76 | result.success(s); 77 | } 78 | } 79 | }.execute(filePath); 80 | } 81 | 82 | // @TargetApi(Build.VERSION_CODES.M) 83 | // private void checkPermissions(final PermissionsResult result) { 84 | // if (!(registrar.activity().checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) { 85 | // registrar.addRequestPermissionsResultListener(new PluginRegistry.RequestPermissionsResultListener() { 86 | // @Override 87 | // public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 88 | // if (requestCode == REQUEST_CODE_CAMERA_PERMISSION) { 89 | // for (int i = 0; i < permissions.length; i++) { 90 | // String permission = permissions[i]; 91 | // int grantResult = grantResults[i]; 92 | // 93 | // if (permission.equals(Manifest.permission.CAMERA)) { 94 | // if (grantResult == PackageManager.PERMISSION_GRANTED) { 95 | // result.onSuccess(); 96 | // } else { 97 | // result.onError(); 98 | // } 99 | // } 100 | // } 101 | // } 102 | // return false; 103 | // } 104 | // }); 105 | // registrar.activity().requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_CODE_CAMERA_PERMISSION); 106 | // } else { 107 | // result.onSuccess(); 108 | // } 109 | // } 110 | } 111 | -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/QRCodeDecoder.java: -------------------------------------------------------------------------------- 1 | package me.hetian.flutter_qr_reader; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.util.Log; 6 | import com.google.zxing.*; 7 | import com.google.zxing.common.GlobalHistogramBinarizer; 8 | import com.google.zxing.common.HybridBinarizer; 9 | import java.util.ArrayList; 10 | import java.util.EnumMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | import me.hetian.flutter_qr_reader.readerView.SimpleLog; 15 | 16 | /** 17 | * 描述:解析二维码图片 18 | */ 19 | public class QRCodeDecoder { 20 | public static final Map HINTS = new EnumMap<>(DecodeHintType.class); 21 | static { 22 | List allFormats = new ArrayList<>(); 23 | allFormats.add(BarcodeFormat.AZTEC); 24 | allFormats.add(BarcodeFormat.CODABAR); 25 | allFormats.add(BarcodeFormat.CODE_39); 26 | allFormats.add(BarcodeFormat.CODE_93); 27 | allFormats.add(BarcodeFormat.CODE_128); 28 | allFormats.add(BarcodeFormat.DATA_MATRIX); 29 | allFormats.add(BarcodeFormat.EAN_8); 30 | allFormats.add(BarcodeFormat.EAN_13); 31 | allFormats.add(BarcodeFormat.ITF); 32 | allFormats.add(BarcodeFormat.MAXICODE); 33 | allFormats.add(BarcodeFormat.PDF_417); 34 | allFormats.add(BarcodeFormat.QR_CODE); 35 | allFormats.add(BarcodeFormat.RSS_14); 36 | allFormats.add(BarcodeFormat.RSS_EXPANDED); 37 | allFormats.add(BarcodeFormat.UPC_A); 38 | allFormats.add(BarcodeFormat.UPC_E); 39 | allFormats.add(BarcodeFormat.UPC_EAN_EXTENSION); 40 | HINTS.put(DecodeHintType.TRY_HARDER, BarcodeFormat.QR_CODE); 41 | HINTS.put(DecodeHintType.POSSIBLE_FORMATS, allFormats); 42 | HINTS.put(DecodeHintType.CHARACTER_SET, "utf-8"); 43 | } 44 | private QRCodeDecoder() { 45 | } 46 | /** 47 | * 同步解析本地图片二维码。该方法是耗时操作,请在子线程中调用。 48 | * 49 | * @param picturePath 要解析的二维码图片本地路径 50 | * @return 返回二维码图片里的内容 或 null 51 | */ 52 | public static String syncDecodeQRCode(String picturePath) { 53 | return syncDecodeQRCode(getDecodeAbleBitmap(picturePath)); 54 | } 55 | /** 56 | * 同步解析bitmap二维码。该方法是耗时操作,请在子线程中调用。 57 | * 58 | * @param bitmap 要解析的二维码图片 59 | * @return 返回二维码图片里的内容 或 null 60 | */ 61 | public static String syncDecodeQRCode(Bitmap bitmap) { 62 | Result result = null; 63 | RGBLuminanceSource source = null; 64 | try { 65 | int width = bitmap.getWidth(); 66 | int height = bitmap.getHeight(); 67 | int[] pixels = new int[width * height]; 68 | bitmap.getPixels(pixels, 0, width, 0, 0, width, height); 69 | source = new RGBLuminanceSource(width, height, pixels); 70 | result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), HINTS); 71 | return result.getText(); 72 | } catch (Exception e) { 73 | if (source != null) { 74 | try { 75 | result = new MultiFormatReader().decode(new BinaryBitmap(new GlobalHistogramBinarizer(source)), HINTS); 76 | return result.getText(); 77 | } catch (Throwable e2) { 78 | MultiFormatReader multiFormatReader = new MultiFormatReader(); 79 | try { 80 | LuminanceSource invertedSource = source.invert(); 81 | BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(invertedSource)); 82 | 83 | result = multiFormatReader.decode(binaryBitmap, HINTS); 84 | return result.getText(); 85 | } catch (NotFoundException exception) { 86 | e.printStackTrace(); 87 | e2.printStackTrace(); 88 | exception.printStackTrace(); 89 | return null; 90 | } finally { 91 | multiFormatReader.reset(); 92 | } 93 | } 94 | } 95 | return null; 96 | } 97 | } 98 | /** 99 | * 将本地图片文件转换成可解码二维码的 Bitmap。为了避免图片太大,这里对图片进行了压缩。感谢 https://github.com/devilsen 提的 PR 100 | * 101 | * @param picturePath 本地图片文件路径 102 | * @return 103 | */ 104 | private static Bitmap getDecodeAbleBitmap(String picturePath) { 105 | try { 106 | BitmapFactory.Options options = new BitmapFactory.Options(); 107 | options.inJustDecodeBounds = true; 108 | BitmapFactory.decodeFile(picturePath, options); 109 | int sampleSize = options.outHeight / 400; 110 | if (sampleSize <= 0) { 111 | sampleSize = 1; 112 | } 113 | options.inSampleSize = sampleSize; 114 | options.inJustDecodeBounds = false; 115 | return BitmapFactory.decodeFile(picturePath, options); 116 | } catch (Exception e) { 117 | Log.d("QR", "NOT FOUND INVERTED"); 118 | return null; 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/factorys/QrReaderFactory.java: -------------------------------------------------------------------------------- 1 | package me.hetian.flutter_qr_reader.factorys; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.Map; 6 | 7 | import io.flutter.plugin.common.PluginRegistry; 8 | import io.flutter.plugin.common.StandardMessageCodec; 9 | import io.flutter.plugin.platform.PlatformView; 10 | import io.flutter.plugin.platform.PlatformViewFactory; 11 | import me.hetian.flutter_qr_reader.views.QrReaderView; 12 | 13 | public class QrReaderFactory extends PlatformViewFactory { 14 | 15 | private PluginRegistry.Registrar registrar; 16 | 17 | public QrReaderFactory(PluginRegistry.Registrar registrar) { 18 | super(StandardMessageCodec.INSTANCE); 19 | this.registrar = registrar; 20 | } 21 | 22 | @Override 23 | public PlatformView create(Context context, int id, Object args) { 24 | Map params = (Map) args; 25 | return new QrReaderView(context, registrar, id, params); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/readerView/Orientation.java: -------------------------------------------------------------------------------- 1 | package me.hetian.flutter_qr_reader.readerView; 2 | 3 | public enum Orientation { 4 | PORTRAIT, LANDSCAPE 5 | } 6 | -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/readerView/QRCodeReaderView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 David Lázaro Esparcia. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package me.hetian.flutter_qr_reader.readerView; 17 | 18 | import android.content.Context; 19 | import android.content.pm.PackageManager; 20 | import android.graphics.Point; 21 | import android.graphics.PointF; 22 | import android.hardware.Camera; 23 | import android.os.AsyncTask; 24 | import android.os.Build; 25 | import android.util.AttributeSet; 26 | import android.view.Surface; 27 | import android.view.SurfaceHolder; 28 | import android.view.SurfaceView; 29 | import android.view.WindowManager; 30 | 31 | import com.google.zxing.BinaryBitmap; 32 | import com.google.zxing.ChecksumException; 33 | import com.google.zxing.DecodeHintType; 34 | import com.google.zxing.FormatException; 35 | import com.google.zxing.LuminanceSource; 36 | import com.google.zxing.MultiFormatReader; 37 | import com.google.zxing.NotFoundException; 38 | import com.google.zxing.PlanarYUVLuminanceSource; 39 | import com.google.zxing.Result; 40 | import com.google.zxing.ResultPoint; 41 | import com.google.zxing.client.android.camera.CameraManager; 42 | import com.google.zxing.common.HybridBinarizer; 43 | import com.google.zxing.qrcode.QRCodeReader; 44 | 45 | import java.io.IOException; 46 | import java.lang.ref.WeakReference; 47 | import java.util.Map; 48 | 49 | import static android.hardware.Camera.getCameraInfo; 50 | import static me.hetian.flutter_qr_reader.QRCodeDecoder.HINTS; 51 | 52 | /** 53 | * QRCodeReaderView Class which uses ZXING lib and let you easily integrate a QR decoder view. 54 | * Take some classes and made some modifications in the original ZXING - Barcode Scanner project. 55 | * 56 | * @author David Lázaro 57 | */ 58 | public class QRCodeReaderView extends SurfaceView 59 | implements SurfaceHolder.Callback, Camera.PreviewCallback { 60 | 61 | public interface OnQRCodeReadListener { 62 | 63 | void onQRCodeRead(String text, PointF[] points); 64 | } 65 | 66 | private OnQRCodeReadListener mOnQRCodeReadListener; 67 | 68 | private static final String TAG = QRCodeReaderView.class.getName(); 69 | 70 | private QRCodeReader mQRCodeReader; 71 | private int mPreviewWidth; 72 | private int mPreviewHeight; 73 | private CameraManager mCameraManager; 74 | private boolean mQrDecodingEnabled = true; 75 | private DecodeFrameTask decodeFrameTask; 76 | private Map decodeHints; 77 | 78 | public QRCodeReaderView(Context context) { 79 | this(context, null); 80 | } 81 | 82 | public QRCodeReaderView(Context context, AttributeSet attrs) { 83 | super(context, attrs); 84 | 85 | if (isInEditMode()) { 86 | return; 87 | } 88 | 89 | if (checkCameraHardware()) { 90 | mCameraManager = new CameraManager(getContext()); 91 | mCameraManager.setPreviewCallback(this); 92 | getHolder().addCallback(this); 93 | setBackCamera(); 94 | } else { 95 | throw new RuntimeException("Error: Camera not found"); 96 | } 97 | } 98 | 99 | /** 100 | * Set the callback to return decoding result 101 | * 102 | * @param onQRCodeReadListener the listener 103 | */ 104 | public void setOnQRCodeReadListener(OnQRCodeReadListener onQRCodeReadListener) { 105 | mOnQRCodeReadListener = onQRCodeReadListener; 106 | } 107 | 108 | /** 109 | * Enable/disable logging, false by default 110 | * 111 | * @param enabled logging enabled/disabled. 112 | */ 113 | public void setLoggingEnabled(boolean enabled) { 114 | SimpleLog.setLoggingEnabled(enabled); 115 | } 116 | 117 | /** 118 | * Set QR decoding enabled/disabled. 119 | * default value is true 120 | * 121 | * @param qrDecodingEnabled decoding enabled/disabled. 122 | */ 123 | public void setQRDecodingEnabled(boolean qrDecodingEnabled) { 124 | this.mQrDecodingEnabled = qrDecodingEnabled; 125 | } 126 | 127 | /** 128 | * Set QR hints required for decoding 129 | * 130 | * @param decodeHints hints for decoding qrcode 131 | */ 132 | public void setDecodeHints(Map decodeHints) { 133 | this.decodeHints = decodeHints; 134 | } 135 | 136 | /** 137 | * Starts google.zxing.client.android.android.com.google.zxing.client.android.camera preview and decoding 138 | */ 139 | public void startCamera() { 140 | mCameraManager.startPreview(); 141 | } 142 | 143 | /** 144 | * Stop google.zxing.client.android.android.com.google.zxing.client.android.camera preview and decoding 145 | */ 146 | public void stopCamera() { 147 | mCameraManager.stopPreview(); 148 | } 149 | 150 | /** 151 | * Set Camera autofocus interval value 152 | * default value is 5000 ms. 153 | * 154 | * @param autofocusIntervalInMs autofocus interval value 155 | */ 156 | public void setAutofocusInterval(long autofocusIntervalInMs) { 157 | if (mCameraManager != null) { 158 | mCameraManager.setAutofocusInterval(autofocusIntervalInMs); 159 | } 160 | } 161 | 162 | /** 163 | * Trigger an auto focus 164 | */ 165 | public void forceAutoFocus() { 166 | if (mCameraManager != null) { 167 | mCameraManager.forceAutoFocus(); 168 | } 169 | } 170 | 171 | /** 172 | * Set Torch enabled/disabled. 173 | * default value is false 174 | * 175 | * @param enabled torch enabled/disabled. 176 | */ 177 | public void setTorchEnabled(boolean enabled) { 178 | if (mCameraManager != null) { 179 | mCameraManager.setTorchEnabled(enabled); 180 | } 181 | } 182 | 183 | /** 184 | * Allows user to specify the google.zxing.client.android.android.com.google.zxing.client.android.camera ID, rather than determine 185 | * it automatically based on available cameras and their orientation. 186 | * 187 | * @param cameraId google.zxing.client.android.android.com.google.zxing.client.android.camera ID of the google.zxing.client.android.android.com.google.zxing.client.android.camera to use. A negative value means "no preference". 188 | */ 189 | public void setPreviewCameraId(int cameraId) { 190 | mCameraManager.setPreviewCameraId(cameraId); 191 | } 192 | 193 | /** 194 | * Camera preview from device back google.zxing.client.android.android.com.google.zxing.client.android.camera 195 | */ 196 | public void setBackCamera() { 197 | setPreviewCameraId(Camera.CameraInfo.CAMERA_FACING_BACK); 198 | } 199 | 200 | /** 201 | * Camera preview from device front google.zxing.client.android.android.com.google.zxing.client.android.camera 202 | */ 203 | public void setFrontCamera() { 204 | setPreviewCameraId(Camera.CameraInfo.CAMERA_FACING_FRONT); 205 | } 206 | 207 | @Override 208 | public void onDetachedFromWindow() { 209 | super.onDetachedFromWindow(); 210 | 211 | if (decodeFrameTask != null) { 212 | decodeFrameTask.cancel(true); 213 | decodeFrameTask = null; 214 | } 215 | } 216 | 217 | /**************************************************** 218 | * SurfaceHolder.Callback,Camera.PreviewCallback 219 | ****************************************************/ 220 | 221 | @Override 222 | public void surfaceCreated(SurfaceHolder holder) { 223 | SimpleLog.d(TAG, "surfaceCreated"); 224 | 225 | try { 226 | // Indicate google.zxing.client.android.android.com.google.zxing.client.android.camera, our View dimensions 227 | mCameraManager.openDriver(holder, this.getWidth(), this.getHeight()); 228 | } catch (IOException | RuntimeException e) { 229 | SimpleLog.w(TAG, "Can not openDriver: " + e.getMessage()); 230 | mCameraManager.closeDriver(); 231 | } 232 | 233 | try { 234 | mQRCodeReader = new QRCodeReader(); 235 | mCameraManager.startPreview(); 236 | } catch (Exception e) { 237 | SimpleLog.e(TAG, "Exception: " + e.getMessage()); 238 | mCameraManager.closeDriver(); 239 | } 240 | } 241 | 242 | @Override 243 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 244 | SimpleLog.d(TAG, "surfaceChanged"); 245 | 246 | if (holder.getSurface() == null) { 247 | SimpleLog.e(TAG, "Error: preview surface does not exist"); 248 | return; 249 | } 250 | 251 | if (mCameraManager.getPreviewSize() == null) { 252 | SimpleLog.e(TAG, "Error: preview size does not exist"); 253 | return; 254 | } 255 | 256 | mPreviewWidth = mCameraManager.getPreviewSize().x; 257 | mPreviewHeight = mCameraManager.getPreviewSize().y; 258 | 259 | mCameraManager.stopPreview(); 260 | 261 | // Fix the google.zxing.client.android.android.com.google.zxing.client.android.camera sensor rotation 262 | mCameraManager.setPreviewCallback(this); 263 | mCameraManager.setDisplayOrientation(getCameraDisplayOrientation()); 264 | 265 | mCameraManager.startPreview(); 266 | } 267 | 268 | @Override 269 | public void surfaceDestroyed(SurfaceHolder holder) { 270 | SimpleLog.d(TAG, "surfaceDestroyed"); 271 | 272 | mCameraManager.setPreviewCallback(null); 273 | mCameraManager.stopPreview(); 274 | mCameraManager.closeDriver(); 275 | } 276 | 277 | // Called when google.zxing.client.android.android.com.google.zxing.client.android.camera take a frame 278 | @Override 279 | public void onPreviewFrame(byte[] data, Camera camera) { 280 | if (!mQrDecodingEnabled || decodeFrameTask != null 281 | && (decodeFrameTask.getStatus() == AsyncTask.Status.RUNNING 282 | || decodeFrameTask.getStatus() == AsyncTask.Status.PENDING)) { 283 | return; 284 | } 285 | 286 | decodeFrameTask = new DecodeFrameTask(this, decodeHints); 287 | decodeFrameTask.execute(data); 288 | } 289 | 290 | /** 291 | * Check if this device has a google.zxing.client.android.android.com.google.zxing.client.android.camera 292 | */ 293 | private boolean checkCameraHardware() { 294 | if (getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) { 295 | // this device has a google.zxing.client.android.android.com.google.zxing.client.android.camera 296 | return true; 297 | } else if (getContext().getPackageManager() 298 | .hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) { 299 | // this device has a front google.zxing.client.android.android.com.google.zxing.client.android.camera 300 | return true; 301 | } else { 302 | // this device has any google.zxing.client.android.android.com.google.zxing.client.android.camera 303 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 304 | && getContext().getPackageManager().hasSystemFeature( 305 | PackageManager.FEATURE_CAMERA_ANY); 306 | } 307 | } 308 | 309 | /** 310 | * Fix for the google.zxing.client.android.android.com.google.zxing.client.android.camera Sensor on some devices (ex.: Nexus 5x) 311 | */ 312 | @SuppressWarnings("deprecation") 313 | private int getCameraDisplayOrientation() { 314 | 315 | Camera.CameraInfo info = new Camera.CameraInfo(); 316 | getCameraInfo(mCameraManager.getPreviewCameraId(), info); 317 | WindowManager windowManager = 318 | (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); 319 | int rotation = windowManager.getDefaultDisplay().getRotation(); 320 | int degrees = 0; 321 | switch (rotation) { 322 | case Surface.ROTATION_0: 323 | degrees = 0; 324 | break; 325 | case Surface.ROTATION_90: 326 | degrees = 90; 327 | break; 328 | case Surface.ROTATION_180: 329 | degrees = 180; 330 | break; 331 | case Surface.ROTATION_270: 332 | degrees = 270; 333 | break; 334 | default: 335 | break; 336 | } 337 | 338 | int result; 339 | if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { 340 | result = (info.orientation + degrees) % 360; 341 | result = (360 - result) % 360; // compensate the mirror 342 | } else { // back-facing 343 | result = (info.orientation - degrees + 360) % 360; 344 | } 345 | return result; 346 | } 347 | 348 | private static class DecodeFrameTask extends AsyncTask { 349 | 350 | private final WeakReference viewRef; 351 | private final WeakReference> hintsRef; 352 | private final QRToViewPointTransformer qrToViewPointTransformer = 353 | new QRToViewPointTransformer(); 354 | 355 | DecodeFrameTask(QRCodeReaderView view, Map hints) { 356 | viewRef = new WeakReference<>(view); 357 | hintsRef = new WeakReference<>(hints); 358 | } 359 | 360 | @Override 361 | protected Result doInBackground(byte[]... params) { 362 | final QRCodeReaderView view = viewRef.get(); 363 | if (view == null) { 364 | return null; 365 | } 366 | 367 | final PlanarYUVLuminanceSource source = 368 | view.mCameraManager.buildLuminanceSource(params[0], view.mPreviewWidth, 369 | view.mPreviewHeight); 370 | 371 | final HybridBinarizer hybBin = new HybridBinarizer(source); 372 | final BinaryBitmap bitmap = new BinaryBitmap(hybBin); 373 | 374 | try { 375 | return view.mQRCodeReader.decode(bitmap, hintsRef.get()); 376 | } catch (ChecksumException e) { 377 | SimpleLog.d(TAG, "ChecksumException", e); 378 | } catch (NotFoundException e) { 379 | MultiFormatReader multiFormatReader = new MultiFormatReader(); 380 | try { 381 | SimpleLog.d(TAG, "No QR Code found"); 382 | 383 | LuminanceSource invertedSource = source.invert(); 384 | BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(invertedSource)); 385 | 386 | return multiFormatReader.decode(binaryBitmap, HINTS); 387 | } catch (NotFoundException exception) { 388 | SimpleLog.d(TAG, "No Inverted QR Code found"); 389 | return null; 390 | } finally { 391 | multiFormatReader.reset(); 392 | } 393 | } catch (FormatException e) { 394 | SimpleLog.d(TAG, "FormatException", e); 395 | } finally { 396 | view.mQRCodeReader.reset(); 397 | } 398 | 399 | return null; 400 | } 401 | 402 | @Override 403 | protected void onPostExecute(Result result) { 404 | super.onPostExecute(result); 405 | 406 | final QRCodeReaderView view = viewRef.get(); 407 | 408 | // Notify we found a QRCode 409 | if (view != null && result != null && view.mOnQRCodeReadListener != null) { 410 | // Transform resultPoints to View coordinates 411 | final PointF[] transformedPoints = 412 | transformToViewCoordinates(view, result.getResultPoints()); 413 | view.mOnQRCodeReadListener.onQRCodeRead(result.getText(), transformedPoints); 414 | } 415 | } 416 | 417 | /** 418 | * Transform result to surfaceView coordinates 419 | *

420 | * This method is needed because coordinates are given in landscape google.zxing.client.android.android.com.google.zxing.client.android.camera coordinates when 421 | * device is in portrait mode and different coordinates otherwise. 422 | * 423 | * @return a new PointF array with transformed points 424 | */ 425 | private PointF[] transformToViewCoordinates(QRCodeReaderView view, 426 | ResultPoint[] resultPoints) { 427 | int orientationDegrees = view.getCameraDisplayOrientation(); 428 | Orientation orientation = 429 | orientationDegrees == 90 || orientationDegrees == 270 ? Orientation.PORTRAIT 430 | : Orientation.LANDSCAPE; 431 | Point viewSize = new Point(view.getWidth(), view.getHeight()); 432 | Point cameraPreviewSize = view.mCameraManager.getPreviewSize(); 433 | boolean isMirrorCamera = 434 | view.mCameraManager.getPreviewCameraId() 435 | == Camera.CameraInfo.CAMERA_FACING_FRONT; 436 | 437 | return qrToViewPointTransformer.transform(resultPoints, isMirrorCamera, orientation, 438 | viewSize, cameraPreviewSize); 439 | } 440 | } 441 | } 442 | -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/readerView/QRToViewPointTransformer.java: -------------------------------------------------------------------------------- 1 | package me.hetian.flutter_qr_reader.readerView; 2 | 3 | import android.graphics.Point; 4 | import android.graphics.PointF; 5 | 6 | import com.google.zxing.ResultPoint; 7 | 8 | public class QRToViewPointTransformer { 9 | 10 | public PointF[] transform(ResultPoint[] qrPoints, boolean isMirrorPreview, 11 | Orientation orientation, 12 | Point viewSize, Point cameraPreviewSize) { 13 | PointF[] transformedPoints = new PointF[qrPoints.length]; 14 | int index = 0; 15 | for (ResultPoint qrPoint : qrPoints) { 16 | PointF transformedPoint = transform(qrPoint, isMirrorPreview, orientation, viewSize, 17 | cameraPreviewSize); 18 | transformedPoints[index] = transformedPoint; 19 | index++; 20 | } 21 | return transformedPoints; 22 | } 23 | 24 | public PointF transform(ResultPoint qrPoint, boolean isMirrorPreview, Orientation orientation, 25 | Point viewSize, Point cameraPreviewSize) { 26 | float previewX = cameraPreviewSize.x; 27 | float previewY = cameraPreviewSize.y; 28 | 29 | PointF transformedPoint = null; 30 | float scaleX; 31 | float scaleY; 32 | 33 | if (orientation == Orientation.PORTRAIT) { 34 | scaleX = viewSize.x / previewY; 35 | scaleY = viewSize.y / previewX; 36 | transformedPoint = new PointF((previewY - qrPoint.getY()) * scaleX, qrPoint.getX() * scaleY); 37 | if (isMirrorPreview) { 38 | transformedPoint.y = viewSize.y - transformedPoint.y; 39 | } 40 | } else if (orientation == Orientation.LANDSCAPE) { 41 | scaleX = viewSize.x / previewX; 42 | scaleY = viewSize.y / previewY; 43 | transformedPoint = new PointF(viewSize.x - qrPoint.getX() * scaleX, 44 | viewSize.y - qrPoint.getY() * scaleY); 45 | if (isMirrorPreview) { 46 | transformedPoint.x = viewSize.x - transformedPoint.x; 47 | } 48 | } 49 | return transformedPoint; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/readerView/README.md: -------------------------------------------------------------------------------- 1 | copy:https://github.com/dlazaro66/QRCodeReaderView -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/readerView/SimpleLog.java: -------------------------------------------------------------------------------- 1 | package me.hetian.flutter_qr_reader.readerView; 2 | 3 | import android.util.Log; 4 | 5 | public class SimpleLog { 6 | 7 | private static boolean loggingEnabled = false; 8 | 9 | public static void setLoggingEnabled(boolean enabled) { 10 | loggingEnabled = enabled; 11 | } 12 | 13 | public static void d(String tag, String text) { 14 | if (loggingEnabled) { 15 | Log.d(tag, text); 16 | } 17 | } 18 | 19 | public static void w(String tag, String text) { 20 | if (loggingEnabled) { 21 | Log.w(tag, text); 22 | } 23 | } 24 | 25 | public static void w(String tag, String text, Throwable e) { 26 | if (loggingEnabled) { 27 | Log.w(tag, text, e); 28 | } 29 | } 30 | 31 | public static void e(String tag, String text) { 32 | if (loggingEnabled) { 33 | Log.e(tag, text); 34 | } 35 | } 36 | 37 | public static void d(String tag, String text, Throwable e) { 38 | if (loggingEnabled) { 39 | Log.d(tag, text, e); 40 | } 41 | } 42 | 43 | public static void i(String tag, String text) { 44 | if (loggingEnabled) { 45 | Log.i(tag, text); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /android/src/main/java/me/hetian/flutter_qr_reader/views/QrReaderView.java: -------------------------------------------------------------------------------- 1 | package me.hetian.flutter_qr_reader.views; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.ActionBar; 5 | import android.content.Context; 6 | import android.graphics.PointF; 7 | import android.hardware.Camera; 8 | import android.view.View; 9 | 10 | import com.google.zxing.client.android.camera.CameraManager; 11 | 12 | import java.util.ArrayList; 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | import io.flutter.plugin.common.MethodCall; 17 | import io.flutter.plugin.common.MethodChannel; 18 | import io.flutter.plugin.common.PluginRegistry; 19 | import io.flutter.plugin.platform.PlatformView; 20 | import me.hetian.flutter_qr_reader.readerView.QRCodeReaderView; 21 | 22 | public class QrReaderView implements PlatformView, QRCodeReaderView.OnQRCodeReadListener, MethodChannel.MethodCallHandler { 23 | 24 | private final MethodChannel mMethodChannel; 25 | private final Context mContext; 26 | private Map mParams; 27 | private PluginRegistry.Registrar mRegistrar; 28 | QRCodeReaderView _view; 29 | 30 | public static String EXTRA_FOCUS_INTERVAL = "extra_focus_interval"; 31 | public static String EXTRA_TORCH_ENABLED = "extra_torch_enabled"; 32 | 33 | public QrReaderView(Context context, PluginRegistry.Registrar registrar, int id, Map params){ 34 | this.mContext = context; 35 | this.mParams = params; 36 | this.mRegistrar = registrar; 37 | 38 | // 创建视图 39 | int width = (int) mParams.get("width"); 40 | int height = (int) mParams.get("height"); 41 | _view = new QRCodeReaderView(mContext); 42 | ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(width, height); 43 | _view.setLayoutParams(layoutParams); 44 | _view.setOnQRCodeReadListener(this); 45 | _view.setQRDecodingEnabled(true); 46 | _view.forceAutoFocus(); 47 | int interval = mParams.containsKey(EXTRA_FOCUS_INTERVAL) ? (int) mParams.get(EXTRA_FOCUS_INTERVAL) : 2000; 48 | _view.setAutofocusInterval(interval); 49 | _view.setTorchEnabled((boolean)mParams.get(EXTRA_TORCH_ENABLED)); 50 | 51 | // 操作监听 52 | mMethodChannel = new MethodChannel(registrar.messenger(), "me.hetian.flutter_qr_reader.reader_view_" + id); 53 | mMethodChannel.setMethodCallHandler(this); 54 | } 55 | 56 | @Override 57 | public View getView() { 58 | return _view; 59 | } 60 | 61 | @Override 62 | public void dispose() { 63 | _view = null; 64 | mParams = null; 65 | mRegistrar = null; 66 | } 67 | 68 | @Override 69 | public void onQRCodeRead(String text, PointF[] points) { 70 | HashMap rest = new HashMap(); 71 | rest.put("text", text); 72 | ArrayList poi = new ArrayList(); 73 | for (PointF point : points) { 74 | poi.add(point.x + "," + point.y); 75 | } 76 | rest.put("points", poi); 77 | mMethodChannel.invokeMethod("onQRCodeRead", rest); 78 | } 79 | 80 | boolean flashlight; 81 | @Override 82 | public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { 83 | switch (methodCall.method) { 84 | case "flashlight": 85 | _view.setTorchEnabled(!flashlight); 86 | flashlight = !flashlight; 87 | result.success(flashlight); 88 | break; 89 | case "startCamera": 90 | _view.startCamera(); 91 | break; 92 | case "stopCamera": 93 | _view.stopCamera(); 94 | break; 95 | } 96 | 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /assets/tool_flashlight_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/assets/tool_flashlight_close.png -------------------------------------------------------------------------------- /assets/tool_flashlight_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/assets/tool_flashlight_open.png -------------------------------------------------------------------------------- /assets/tool_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/assets/tool_img.png -------------------------------------------------------------------------------- /assets/tool_qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/assets/tool_qrcode.png -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .packages 28 | .pub-cache/ 29 | .pub/ 30 | /build/ 31 | 32 | # Android related 33 | **/android/**/gradle-wrapper.jar 34 | **/android/.gradle 35 | **/android/captures/ 36 | **/android/gradlew 37 | **/android/gradlew.bat 38 | **/android/local.properties 39 | **/android/**/GeneratedPluginRegistrant.java 40 | 41 | # iOS/XCode related 42 | **/ios/**/*.mode1v3 43 | **/ios/**/*.mode2v3 44 | **/ios/**/*.moved-aside 45 | **/ios/**/*.pbxuser 46 | **/ios/**/*.perspectivev3 47 | **/ios/**/*sync/ 48 | **/ios/**/.sconsign.dblite 49 | **/ios/**/.tags* 50 | **/ios/**/.vagrant/ 51 | **/ios/**/DerivedData/ 52 | **/ios/**/Icon? 53 | **/ios/**/Pods/ 54 | **/ios/**/.symlinks/ 55 | **/ios/**/profile 56 | **/ios/**/xcuserdata 57 | **/ios/.generated/ 58 | **/ios/Flutter/App.framework 59 | **/ios/Flutter/Flutter.framework 60 | **/ios/Flutter/Generated.xcconfig 61 | **/ios/Flutter/app.flx 62 | **/ios/Flutter/app.zip 63 | **/ios/Flutter/flutter_assets/ 64 | **/ios/ServiceDefinitions.json 65 | **/ios/Runner/GeneratedPluginRegistrant.* 66 | 67 | # Exceptions to above rules. 68 | !**/ios/**/default.mode1v3 69 | !**/ios/**/default.mode2v3 70 | !**/ios/**/default.pbxuser 71 | !**/ios/**/default.perspectivev3 72 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 73 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: b3b6d03737bd3f61209570e86f2b045c80f35c44 8 | channel: dev 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # flutter_qr_reader_example 2 | 3 | Demonstrates how to use the flutter_qr_reader plugin. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.dev/docs), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 26 | 27 | android { 28 | compileSdkVersion 28 29 | 30 | lintOptions { 31 | disable 'InvalidPackage' 32 | } 33 | 34 | defaultConfig { 35 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 36 | applicationId "me.hetian.flutter_qr_reader_example" 37 | minSdkVersion 16 38 | targetSdkVersion 28 39 | versionCode flutterVersionCode.toInteger() 40 | versionName flutterVersionName 41 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 42 | } 43 | 44 | buildTypes { 45 | release { 46 | // TODO: Add your own signing config for the release build. 47 | // Signing with the debug keys for now, so `flutter run --release` works. 48 | signingConfig signingConfigs.debug 49 | } 50 | } 51 | } 52 | 53 | flutter { 54 | source '../..' 55 | } 56 | 57 | dependencies { 58 | testImplementation 'junit:junit:4.12' 59 | androidTestImplementation 'androidx.test:runner:1.1.0' 60 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' 61 | } 62 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 14 | 18 | 25 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/me/hetian/flutter_qr_reader_example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package me.hetian.flutter_qr_reader_example; 2 | 3 | import android.os.Bundle; 4 | import io.flutter.app.FlutterActivity; 5 | import io.flutter.plugins.GeneratedPluginRegistrant; 6 | 7 | public class MainActivity extends FlutterActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | GeneratedPluginRegistrant.registerWith(this); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.3.1' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | google() 15 | jcenter() 16 | } 17 | } 18 | 19 | rootProject.buildDir = '../build' 20 | subprojects { 21 | project.buildDir = "${rootProject.buildDir}/${project.name}" 22 | } 23 | subprojects { 24 | project.evaluationDependsOn(':app') 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | android.enableJetifier=true 2 | android.useAndroidX=true 3 | org.gradle.jvmargs=-Xmx1536M 4 | 5 | android.enableR8=true 6 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip 7 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() 4 | 5 | def plugins = new Properties() 6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') 7 | if (pluginsFile.exists()) { 8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } 9 | } 10 | 11 | plugins.each { name, path -> 12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() 13 | include ":$name" 14 | project(":$name").projectDir = pluginDirectory 15 | } 16 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 8.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def parse_KV_file(file, separator='=') 14 | file_abs_path = File.expand_path(file) 15 | if !File.exists? file_abs_path 16 | return []; 17 | end 18 | pods_ary = [] 19 | skip_line_start_symbols = ["#", "/"] 20 | File.foreach(file_abs_path) { |line| 21 | next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } 22 | plugin = line.split(pattern=separator) 23 | if plugin.length == 2 24 | podname = plugin[0].strip() 25 | path = plugin[1].strip() 26 | podpath = File.expand_path("#{path}", file_abs_path) 27 | pods_ary.push({:name => podname, :path => podpath}); 28 | else 29 | puts "Invalid plugin specification: #{line}" 30 | end 31 | } 32 | return pods_ary 33 | end 34 | 35 | target 'Runner' do 36 | # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock 37 | # referring to absolute paths on developers' machines. 38 | system('rm -rf .symlinks') 39 | system('mkdir -p .symlinks/plugins') 40 | 41 | # Flutter Pods 42 | generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig') 43 | if generated_xcode_build_settings.empty? 44 | puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first." 45 | end 46 | generated_xcode_build_settings.map { |p| 47 | if p[:name] == 'FLUTTER_FRAMEWORK_DIR' 48 | symlink = File.join('.symlinks', 'flutter') 49 | File.symlink(File.dirname(p[:path]), symlink) 50 | pod 'Flutter', :path => File.join(symlink, File.basename(p[:path])) 51 | end 52 | } 53 | 54 | # Plugin Pods 55 | plugin_pods = parse_KV_file('../.flutter-plugins') 56 | plugin_pods.map { |p| 57 | symlink = File.join('.symlinks', 'plugins', p[:name]) 58 | File.symlink(p[:path], symlink) 59 | pod p[:name], :path => File.join(symlink, 'ios') 60 | } 61 | end 62 | 63 | post_install do |installer| 64 | installer.pods_project.targets.each do |target| 65 | target.build_configurations.each do |config| 66 | config.build_settings['ENABLE_BITCODE'] = 'NO' 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Flutter (1.0.0) 3 | - flutter_qr_reader (0.0.1): 4 | - Flutter 5 | - image_picker (0.0.1): 6 | - Flutter 7 | - permission_handler (3.1.0): 8 | - Flutter 9 | 10 | DEPENDENCIES: 11 | - Flutter (from `.symlinks/flutter/ios`) 12 | - flutter_qr_reader (from `.symlinks/plugins/flutter_qr_reader/ios`) 13 | - image_picker (from `.symlinks/plugins/image_picker/ios`) 14 | - permission_handler (from `.symlinks/plugins/permission_handler/ios`) 15 | 16 | EXTERNAL SOURCES: 17 | Flutter: 18 | :path: ".symlinks/flutter/ios" 19 | flutter_qr_reader: 20 | :path: ".symlinks/plugins/flutter_qr_reader/ios" 21 | image_picker: 22 | :path: ".symlinks/plugins/image_picker/ios" 23 | permission_handler: 24 | :path: ".symlinks/plugins/permission_handler/ios" 25 | 26 | SPEC CHECKSUMS: 27 | Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296 28 | flutter_qr_reader: cb791fdc527672537c644b2080196237bac85dfa 29 | image_picker: 86b84c4fe89267356a1f17297a45b5d317ebd2e7 30 | permission_handler: a1b8c0f8c83b4e7201f9c04b9aef09979cc97f60 31 | 32 | PODFILE CHECKSUM: e8988baac3a50f787b9d3ed7ca44957b442f92a7 33 | 34 | COCOAPODS: 1.5.3 35 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 12 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 13 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 14 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 15 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 16 | 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 17 | 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 18 | 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 19 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 20 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 21 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 22 | 9C1E29AF6A342B906797DE1E /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 609EE3FBD7BBC40F3A6BE32C /* libPods-Runner.a */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXCopyFilesBuildPhase section */ 26 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 27 | isa = PBXCopyFilesBuildPhase; 28 | buildActionMask = 2147483647; 29 | dstPath = ""; 30 | dstSubfolderSpec = 10; 31 | files = ( 32 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, 33 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, 34 | ); 35 | name = "Embed Frameworks"; 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXCopyFilesBuildPhase section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 42 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 43 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 44 | 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 45 | 609EE3FBD7BBC40F3A6BE32C /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 47 | 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 48 | 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 49 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 50 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 51 | 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 52 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 54 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 55 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 56 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 57 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 58 | /* End PBXFileReference section */ 59 | 60 | /* Begin PBXFrameworksBuildPhase section */ 61 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 66 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, 67 | 9C1E29AF6A342B906797DE1E /* libPods-Runner.a in Frameworks */, 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | /* End PBXFrameworksBuildPhase section */ 72 | 73 | /* Begin PBXGroup section */ 74 | 41B3147FE4618AF8430B6376 /* Frameworks */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 609EE3FBD7BBC40F3A6BE32C /* libPods-Runner.a */, 78 | ); 79 | name = Frameworks; 80 | sourceTree = ""; 81 | }; 82 | 6B70193001E3453BA92650CB /* Pods */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | ); 86 | name = Pods; 87 | sourceTree = ""; 88 | }; 89 | 9740EEB11CF90186004384FC /* Flutter */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 3B80C3931E831B6300D905FE /* App.framework */, 93 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 94 | 9740EEBA1CF902C7004384FC /* Flutter.framework */, 95 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 96 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 97 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 98 | ); 99 | name = Flutter; 100 | sourceTree = ""; 101 | }; 102 | 97C146E51CF9000F007C117D = { 103 | isa = PBXGroup; 104 | children = ( 105 | 9740EEB11CF90186004384FC /* Flutter */, 106 | 97C146F01CF9000F007C117D /* Runner */, 107 | 97C146EF1CF9000F007C117D /* Products */, 108 | 6B70193001E3453BA92650CB /* Pods */, 109 | 41B3147FE4618AF8430B6376 /* Frameworks */, 110 | ); 111 | sourceTree = ""; 112 | }; 113 | 97C146EF1CF9000F007C117D /* Products */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 97C146EE1CF9000F007C117D /* Runner.app */, 117 | ); 118 | name = Products; 119 | sourceTree = ""; 120 | }; 121 | 97C146F01CF9000F007C117D /* Runner */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, 125 | 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, 126 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 127 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 128 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 129 | 97C147021CF9000F007C117D /* Info.plist */, 130 | 97C146F11CF9000F007C117D /* Supporting Files */, 131 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 132 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 133 | ); 134 | path = Runner; 135 | sourceTree = ""; 136 | }; 137 | 97C146F11CF9000F007C117D /* Supporting Files */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | 97C146F21CF9000F007C117D /* main.m */, 141 | ); 142 | name = "Supporting Files"; 143 | sourceTree = ""; 144 | }; 145 | /* End PBXGroup section */ 146 | 147 | /* Begin PBXNativeTarget section */ 148 | 97C146ED1CF9000F007C117D /* Runner */ = { 149 | isa = PBXNativeTarget; 150 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 151 | buildPhases = ( 152 | FE00275F0DF8F0C5DE8C24A3 /* [CP] Check Pods Manifest.lock */, 153 | 9740EEB61CF901F6004384FC /* Run Script */, 154 | 97C146EA1CF9000F007C117D /* Sources */, 155 | 97C146EB1CF9000F007C117D /* Frameworks */, 156 | 97C146EC1CF9000F007C117D /* Resources */, 157 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 158 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 159 | 50436DDA28C48A7C620C513D /* [CP] Embed Pods Frameworks */, 160 | ); 161 | buildRules = ( 162 | ); 163 | dependencies = ( 164 | ); 165 | name = Runner; 166 | productName = Runner; 167 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 168 | productType = "com.apple.product-type.application"; 169 | }; 170 | /* End PBXNativeTarget section */ 171 | 172 | /* Begin PBXProject section */ 173 | 97C146E61CF9000F007C117D /* Project object */ = { 174 | isa = PBXProject; 175 | attributes = { 176 | LastUpgradeCheck = 0910; 177 | ORGANIZATIONNAME = "The Chromium Authors"; 178 | TargetAttributes = { 179 | 97C146ED1CF9000F007C117D = { 180 | CreatedOnToolsVersion = 7.3.1; 181 | DevelopmentTeam = Y5H7257JB2; 182 | }; 183 | }; 184 | }; 185 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 186 | compatibilityVersion = "Xcode 3.2"; 187 | developmentRegion = English; 188 | hasScannedForEncodings = 0; 189 | knownRegions = ( 190 | en, 191 | Base, 192 | ); 193 | mainGroup = 97C146E51CF9000F007C117D; 194 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 195 | projectDirPath = ""; 196 | projectRoot = ""; 197 | targets = ( 198 | 97C146ED1CF9000F007C117D /* Runner */, 199 | ); 200 | }; 201 | /* End PBXProject section */ 202 | 203 | /* Begin PBXResourcesBuildPhase section */ 204 | 97C146EC1CF9000F007C117D /* Resources */ = { 205 | isa = PBXResourcesBuildPhase; 206 | buildActionMask = 2147483647; 207 | files = ( 208 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 209 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 210 | 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 211 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 212 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 213 | ); 214 | runOnlyForDeploymentPostprocessing = 0; 215 | }; 216 | /* End PBXResourcesBuildPhase section */ 217 | 218 | /* Begin PBXShellScriptBuildPhase section */ 219 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 220 | isa = PBXShellScriptBuildPhase; 221 | buildActionMask = 2147483647; 222 | files = ( 223 | ); 224 | inputPaths = ( 225 | ); 226 | name = "Thin Binary"; 227 | outputPaths = ( 228 | ); 229 | runOnlyForDeploymentPostprocessing = 0; 230 | shellPath = /bin/sh; 231 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; 232 | }; 233 | 50436DDA28C48A7C620C513D /* [CP] Embed Pods Frameworks */ = { 234 | isa = PBXShellScriptBuildPhase; 235 | buildActionMask = 2147483647; 236 | files = ( 237 | ); 238 | inputPaths = ( 239 | "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", 240 | "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", 241 | ); 242 | name = "[CP] Embed Pods Frameworks"; 243 | outputPaths = ( 244 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", 245 | ); 246 | runOnlyForDeploymentPostprocessing = 0; 247 | shellPath = /bin/sh; 248 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; 249 | showEnvVarsInLog = 0; 250 | }; 251 | 9740EEB61CF901F6004384FC /* Run Script */ = { 252 | isa = PBXShellScriptBuildPhase; 253 | buildActionMask = 2147483647; 254 | files = ( 255 | ); 256 | inputPaths = ( 257 | ); 258 | name = "Run Script"; 259 | outputPaths = ( 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | shellPath = /bin/sh; 263 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 264 | }; 265 | FE00275F0DF8F0C5DE8C24A3 /* [CP] Check Pods Manifest.lock */ = { 266 | isa = PBXShellScriptBuildPhase; 267 | buildActionMask = 2147483647; 268 | files = ( 269 | ); 270 | inputPaths = ( 271 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 272 | "${PODS_ROOT}/Manifest.lock", 273 | ); 274 | name = "[CP] Check Pods Manifest.lock"; 275 | outputPaths = ( 276 | "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | shellPath = /bin/sh; 280 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 281 | showEnvVarsInLog = 0; 282 | }; 283 | /* End PBXShellScriptBuildPhase section */ 284 | 285 | /* Begin PBXSourcesBuildPhase section */ 286 | 97C146EA1CF9000F007C117D /* Sources */ = { 287 | isa = PBXSourcesBuildPhase; 288 | buildActionMask = 2147483647; 289 | files = ( 290 | 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, 291 | 97C146F31CF9000F007C117D /* main.m in Sources */, 292 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 293 | ); 294 | runOnlyForDeploymentPostprocessing = 0; 295 | }; 296 | /* End PBXSourcesBuildPhase section */ 297 | 298 | /* Begin PBXVariantGroup section */ 299 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 300 | isa = PBXVariantGroup; 301 | children = ( 302 | 97C146FB1CF9000F007C117D /* Base */, 303 | ); 304 | name = Main.storyboard; 305 | sourceTree = ""; 306 | }; 307 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 308 | isa = PBXVariantGroup; 309 | children = ( 310 | 97C147001CF9000F007C117D /* Base */, 311 | ); 312 | name = LaunchScreen.storyboard; 313 | sourceTree = ""; 314 | }; 315 | /* End PBXVariantGroup section */ 316 | 317 | /* Begin XCBuildConfiguration section */ 318 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 319 | isa = XCBuildConfiguration; 320 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 321 | buildSettings = { 322 | ALWAYS_SEARCH_USER_PATHS = NO; 323 | CLANG_ANALYZER_NONNULL = YES; 324 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 325 | CLANG_CXX_LIBRARY = "libc++"; 326 | CLANG_ENABLE_MODULES = YES; 327 | CLANG_ENABLE_OBJC_ARC = YES; 328 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 329 | CLANG_WARN_BOOL_CONVERSION = YES; 330 | CLANG_WARN_COMMA = YES; 331 | CLANG_WARN_CONSTANT_CONVERSION = YES; 332 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 333 | CLANG_WARN_EMPTY_BODY = YES; 334 | CLANG_WARN_ENUM_CONVERSION = YES; 335 | CLANG_WARN_INFINITE_RECURSION = YES; 336 | CLANG_WARN_INT_CONVERSION = YES; 337 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 338 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 339 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 340 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 341 | CLANG_WARN_STRICT_PROTOTYPES = YES; 342 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 343 | CLANG_WARN_UNREACHABLE_CODE = YES; 344 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 345 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 346 | COPY_PHASE_STRIP = NO; 347 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 348 | ENABLE_NS_ASSERTIONS = NO; 349 | ENABLE_STRICT_OBJC_MSGSEND = YES; 350 | GCC_C_LANGUAGE_STANDARD = gnu99; 351 | GCC_NO_COMMON_BLOCKS = YES; 352 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 353 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 354 | GCC_WARN_UNDECLARED_SELECTOR = YES; 355 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 356 | GCC_WARN_UNUSED_FUNCTION = YES; 357 | GCC_WARN_UNUSED_VARIABLE = YES; 358 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 359 | MTL_ENABLE_DEBUG_INFO = NO; 360 | SDKROOT = iphoneos; 361 | TARGETED_DEVICE_FAMILY = "1,2"; 362 | VALIDATE_PRODUCT = YES; 363 | }; 364 | name = Profile; 365 | }; 366 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 367 | isa = XCBuildConfiguration; 368 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 369 | buildSettings = { 370 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 371 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 372 | DEVELOPMENT_TEAM = Y5H7257JB2; 373 | ENABLE_BITCODE = NO; 374 | FRAMEWORK_SEARCH_PATHS = ( 375 | "$(inherited)", 376 | "$(PROJECT_DIR)/Flutter", 377 | ); 378 | INFOPLIST_FILE = Runner/Info.plist; 379 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 380 | LIBRARY_SEARCH_PATHS = ( 381 | "$(inherited)", 382 | "$(PROJECT_DIR)/Flutter", 383 | ); 384 | PRODUCT_BUNDLE_IDENTIFIER = me.hetian.flutterQrReaderExample; 385 | PRODUCT_NAME = "$(TARGET_NAME)"; 386 | VERSIONING_SYSTEM = "apple-generic"; 387 | }; 388 | name = Profile; 389 | }; 390 | 97C147031CF9000F007C117D /* Debug */ = { 391 | isa = XCBuildConfiguration; 392 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 393 | buildSettings = { 394 | ALWAYS_SEARCH_USER_PATHS = NO; 395 | CLANG_ANALYZER_NONNULL = YES; 396 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 397 | CLANG_CXX_LIBRARY = "libc++"; 398 | CLANG_ENABLE_MODULES = YES; 399 | CLANG_ENABLE_OBJC_ARC = YES; 400 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 401 | CLANG_WARN_BOOL_CONVERSION = YES; 402 | CLANG_WARN_COMMA = YES; 403 | CLANG_WARN_CONSTANT_CONVERSION = YES; 404 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 405 | CLANG_WARN_EMPTY_BODY = YES; 406 | CLANG_WARN_ENUM_CONVERSION = YES; 407 | CLANG_WARN_INFINITE_RECURSION = YES; 408 | CLANG_WARN_INT_CONVERSION = YES; 409 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 410 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 411 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 412 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 413 | CLANG_WARN_STRICT_PROTOTYPES = YES; 414 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 415 | CLANG_WARN_UNREACHABLE_CODE = YES; 416 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 417 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 418 | COPY_PHASE_STRIP = NO; 419 | DEBUG_INFORMATION_FORMAT = dwarf; 420 | ENABLE_STRICT_OBJC_MSGSEND = YES; 421 | ENABLE_TESTABILITY = YES; 422 | GCC_C_LANGUAGE_STANDARD = gnu99; 423 | GCC_DYNAMIC_NO_PIC = NO; 424 | GCC_NO_COMMON_BLOCKS = YES; 425 | GCC_OPTIMIZATION_LEVEL = 0; 426 | GCC_PREPROCESSOR_DEFINITIONS = ( 427 | "DEBUG=1", 428 | "$(inherited)", 429 | ); 430 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 431 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 432 | GCC_WARN_UNDECLARED_SELECTOR = YES; 433 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 434 | GCC_WARN_UNUSED_FUNCTION = YES; 435 | GCC_WARN_UNUSED_VARIABLE = YES; 436 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 437 | MTL_ENABLE_DEBUG_INFO = YES; 438 | ONLY_ACTIVE_ARCH = YES; 439 | SDKROOT = iphoneos; 440 | TARGETED_DEVICE_FAMILY = "1,2"; 441 | }; 442 | name = Debug; 443 | }; 444 | 97C147041CF9000F007C117D /* Release */ = { 445 | isa = XCBuildConfiguration; 446 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 447 | buildSettings = { 448 | ALWAYS_SEARCH_USER_PATHS = NO; 449 | CLANG_ANALYZER_NONNULL = YES; 450 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 451 | CLANG_CXX_LIBRARY = "libc++"; 452 | CLANG_ENABLE_MODULES = YES; 453 | CLANG_ENABLE_OBJC_ARC = YES; 454 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 455 | CLANG_WARN_BOOL_CONVERSION = YES; 456 | CLANG_WARN_COMMA = YES; 457 | CLANG_WARN_CONSTANT_CONVERSION = YES; 458 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 459 | CLANG_WARN_EMPTY_BODY = YES; 460 | CLANG_WARN_ENUM_CONVERSION = YES; 461 | CLANG_WARN_INFINITE_RECURSION = YES; 462 | CLANG_WARN_INT_CONVERSION = YES; 463 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 464 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 465 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 466 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 467 | CLANG_WARN_STRICT_PROTOTYPES = YES; 468 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 469 | CLANG_WARN_UNREACHABLE_CODE = YES; 470 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 471 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 472 | COPY_PHASE_STRIP = NO; 473 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 474 | ENABLE_NS_ASSERTIONS = NO; 475 | ENABLE_STRICT_OBJC_MSGSEND = YES; 476 | GCC_C_LANGUAGE_STANDARD = gnu99; 477 | GCC_NO_COMMON_BLOCKS = YES; 478 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 479 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 480 | GCC_WARN_UNDECLARED_SELECTOR = YES; 481 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 482 | GCC_WARN_UNUSED_FUNCTION = YES; 483 | GCC_WARN_UNUSED_VARIABLE = YES; 484 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 485 | MTL_ENABLE_DEBUG_INFO = NO; 486 | SDKROOT = iphoneos; 487 | TARGETED_DEVICE_FAMILY = "1,2"; 488 | VALIDATE_PRODUCT = YES; 489 | }; 490 | name = Release; 491 | }; 492 | 97C147061CF9000F007C117D /* Debug */ = { 493 | isa = XCBuildConfiguration; 494 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 495 | buildSettings = { 496 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 497 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 498 | DEVELOPMENT_TEAM = Y5H7257JB2; 499 | ENABLE_BITCODE = NO; 500 | FRAMEWORK_SEARCH_PATHS = ( 501 | "$(inherited)", 502 | "$(PROJECT_DIR)/Flutter", 503 | ); 504 | INFOPLIST_FILE = Runner/Info.plist; 505 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 506 | LIBRARY_SEARCH_PATHS = ( 507 | "$(inherited)", 508 | "$(PROJECT_DIR)/Flutter", 509 | ); 510 | PRODUCT_BUNDLE_IDENTIFIER = me.hetian.flutterQrReaderExample; 511 | PRODUCT_NAME = "$(TARGET_NAME)"; 512 | VERSIONING_SYSTEM = "apple-generic"; 513 | }; 514 | name = Debug; 515 | }; 516 | 97C147071CF9000F007C117D /* Release */ = { 517 | isa = XCBuildConfiguration; 518 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 519 | buildSettings = { 520 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 521 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 522 | DEVELOPMENT_TEAM = Y5H7257JB2; 523 | ENABLE_BITCODE = NO; 524 | FRAMEWORK_SEARCH_PATHS = ( 525 | "$(inherited)", 526 | "$(PROJECT_DIR)/Flutter", 527 | ); 528 | INFOPLIST_FILE = Runner/Info.plist; 529 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 530 | LIBRARY_SEARCH_PATHS = ( 531 | "$(inherited)", 532 | "$(PROJECT_DIR)/Flutter", 533 | ); 534 | PRODUCT_BUNDLE_IDENTIFIER = me.hetian.flutterQrReaderExample; 535 | PRODUCT_NAME = "$(TARGET_NAME)"; 536 | VERSIONING_SYSTEM = "apple-generic"; 537 | }; 538 | name = Release; 539 | }; 540 | /* End XCBuildConfiguration section */ 541 | 542 | /* Begin XCConfigurationList section */ 543 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 544 | isa = XCConfigurationList; 545 | buildConfigurations = ( 546 | 97C147031CF9000F007C117D /* Debug */, 547 | 97C147041CF9000F007C117D /* Release */, 548 | 249021D3217E4FDB00AE95B9 /* Profile */, 549 | ); 550 | defaultConfigurationIsVisible = 0; 551 | defaultConfigurationName = Release; 552 | }; 553 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 554 | isa = XCConfigurationList; 555 | buildConfigurations = ( 556 | 97C147061CF9000F007C117D /* Debug */, 557 | 97C147071CF9000F007C117D /* Release */, 558 | 249021D4217E4FDB00AE95B9 /* Profile */, 559 | ); 560 | defaultConfigurationIsVisible = 0; 561 | defaultConfigurationName = Release; 562 | }; 563 | /* End XCConfigurationList section */ 564 | }; 565 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 566 | } 567 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 56 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 75 | 77 | 83 | 84 | 85 | 86 | 88 | 89 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildSystemType 6 | Original 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : FlutterAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #include "AppDelegate.h" 2 | #include "GeneratedPluginRegistrant.h" 3 | 4 | @implementation AppDelegate 5 | 6 | - (BOOL)application:(UIApplication *)application 7 | didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 8 | [GeneratedPluginRegistrant registerWithRegistry:self]; 9 | // Override point for customization after application launch. 10 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | io.flutter.embedded_views_preview 6 | 7 | NSPhotoLibraryUsageDescription 8 | 你的操作需要访问照片库权限 9 | NSCameraUsageDescription 10 | 你的操作需要访问相机权限 11 | NSMicrophoneUsageDescription 12 | 你的操作需要访问录像机权限 13 | CFBundleDevelopmentRegion 14 | en 15 | CFBundleExecutable 16 | $(EXECUTABLE_NAME) 17 | CFBundleIdentifier 18 | $(PRODUCT_BUNDLE_IDENTIFIER) 19 | CFBundleInfoDictionaryVersion 20 | 6.0 21 | CFBundleName 22 | flutter_qr_reader_example 23 | CFBundlePackageType 24 | APPL 25 | CFBundleShortVersionString 26 | $(FLUTTER_BUILD_NAME) 27 | CFBundleSignature 28 | ???? 29 | CFBundleVersion 30 | $(FLUTTER_BUILD_NUMBER) 31 | LSRequiresIPhoneOS 32 | 33 | UILaunchStoryboardName 34 | LaunchScreen 35 | UIMainStoryboardFile 36 | Main 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | UISupportedInterfaceOrientations~ipad 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationPortraitUpsideDown 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | UIViewControllerBasedStatusBarAppearance 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /example/ios/Runner/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char* argv[]) { 6 | @autoreleasepool { 7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import 'package:flutter_qr_reader/flutter_qr_reader.dart'; 4 | import 'package:flutter_qr_reader_example/scanViewDemo.dart'; 5 | import 'package:image_picker/image_picker.dart'; 6 | import 'package:permission_handler/permission_handler.dart'; 7 | 8 | void main() => runApp(MyApp()); 9 | 10 | class MyApp extends StatefulWidget { 11 | @override 12 | _MyAppState createState() => _MyAppState(); 13 | } 14 | 15 | class _MyAppState extends State { 16 | @override 17 | void initState() { 18 | super.initState(); 19 | } 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | return MaterialApp(home: HomePage()); 24 | } 25 | } 26 | 27 | class HomePage extends StatefulWidget { 28 | HomePage({Key key}) : super(key: key); 29 | 30 | @override 31 | _HomePageState createState() => new _HomePageState(); 32 | } 33 | 34 | class _HomePageState extends State { 35 | QrReaderViewController _controller; 36 | bool isOk = false; 37 | String data; 38 | @override 39 | void initState() { 40 | super.initState(); 41 | } 42 | 43 | @override 44 | Widget build(BuildContext context) { 45 | return Scaffold( 46 | appBar: AppBar( 47 | title: const Text('Plugin example app'), 48 | ), 49 | body: SingleChildScrollView( 50 | child: Column( 51 | children: [ 52 | FlatButton( 53 | onPressed: () async { 54 | Map permissions = 55 | await PermissionHandler().requestPermissions([PermissionGroup.camera]); 56 | print(permissions); 57 | if (permissions[PermissionGroup.camera] == PermissionStatus.granted) { 58 | showDialog( 59 | context: context, 60 | builder: (context) { 61 | return Dialog( 62 | child: Text("ok"), 63 | ); 64 | }, 65 | ); 66 | setState(() { 67 | isOk = true; 68 | }); 69 | } 70 | }, 71 | child: Text("请求权限"), 72 | color: Colors.blue, 73 | ), 74 | FlatButton( 75 | onPressed: () async { 76 | Navigator.push(context, MaterialPageRoute(builder: (context) => ScanViewDemo())); 77 | }, 78 | child: Text("独立UI"), 79 | ), 80 | FlatButton( 81 | onPressed: () async { 82 | var image = await ImagePicker.pickImage(source: ImageSource.gallery); 83 | if (image == null) return; 84 | final rest = await FlutterQrReader.imgScan(image); 85 | setState(() { 86 | data = rest; 87 | }); 88 | }, 89 | child: Text("识别图片")), 90 | FlatButton( 91 | onPressed: () { 92 | assert(_controller != null); 93 | _controller.setFlashlight(); 94 | }, 95 | child: Text("切换闪光灯")), 96 | FlatButton( 97 | onPressed: () { 98 | assert(_controller != null); 99 | _controller.startCamera(onScan); 100 | }, 101 | child: Text("开始扫码(暂停后)")), 102 | if (data != null) Text(data), 103 | if (isOk) 104 | Container( 105 | width: 320, 106 | height: 350, 107 | child: QrReaderView( 108 | width: 320, 109 | height: 350, 110 | callback: (container) { 111 | this._controller = container; 112 | _controller.startCamera(onScan); 113 | }, 114 | ), 115 | ) 116 | ], 117 | ), 118 | ), 119 | ); 120 | } 121 | 122 | void onScan(String v, List offsets) { 123 | print([v, offsets]); 124 | setState(() { 125 | data = v; 126 | }); 127 | _controller.stopCamera(); 128 | } 129 | 130 | @override 131 | void dispose() { 132 | // TODO: implement dispose 133 | super.dispose(); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /example/lib/scanViewDemo.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/cupertino.dart'; 3 | import 'package:flutter_qr_reader/qrcode_reader_view.dart'; 4 | 5 | class ScanViewDemo extends StatefulWidget { 6 | ScanViewDemo({Key key}) : super(key: key); 7 | 8 | @override 9 | _ScanViewDemoState createState() => new _ScanViewDemoState(); 10 | } 11 | 12 | class _ScanViewDemoState extends State { 13 | GlobalKey _key = GlobalKey(); 14 | @override 15 | void initState() { 16 | super.initState(); 17 | } 18 | 19 | @override 20 | Widget build(BuildContext context) { 21 | return new Scaffold( 22 | body: QrcodeReaderView( 23 | key: _key, 24 | onScan: onScan, 25 | headerWidget: AppBar( 26 | backgroundColor: Colors.transparent, 27 | elevation: 0.0, 28 | ), 29 | ), 30 | ); 31 | } 32 | 33 | Future onScan(String data) async { 34 | await showCupertinoDialog( 35 | context: context, 36 | builder: (context) { 37 | return CupertinoAlertDialog( 38 | title: Text("扫码结果"), 39 | content: Text(data), 40 | actions: [ 41 | CupertinoDialogAction( 42 | child: Text("确认"), 43 | onPressed: () => Navigator.pop(context), 44 | ) 45 | ], 46 | ); 47 | }, 48 | ); 49 | _key.currentState.startScan(); 50 | } 51 | 52 | @override 53 | void dispose() { 54 | super.dispose(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /example/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | archive: 5 | dependency: transitive 6 | description: 7 | name: archive 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.0.11" 11 | args: 12 | dependency: transitive 13 | description: 14 | name: args 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "1.5.2" 18 | async: 19 | dependency: transitive 20 | description: 21 | name: async 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.4.0" 25 | boolean_selector: 26 | dependency: transitive 27 | description: 28 | name: boolean_selector 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "1.0.5" 32 | charcode: 33 | dependency: transitive 34 | description: 35 | name: charcode 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.1.2" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.14.11" 46 | convert: 47 | dependency: transitive 48 | description: 49 | name: convert 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "2.1.1" 53 | crypto: 54 | dependency: transitive 55 | description: 56 | name: crypto 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "2.1.3" 60 | cupertino_icons: 61 | dependency: "direct main" 62 | description: 63 | name: cupertino_icons 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "0.1.3" 67 | flutter: 68 | dependency: "direct main" 69 | description: flutter 70 | source: sdk 71 | version: "0.0.0" 72 | flutter_plugin_android_lifecycle: 73 | dependency: transitive 74 | description: 75 | name: flutter_plugin_android_lifecycle 76 | url: "https://pub.dartlang.org" 77 | source: hosted 78 | version: "1.0.6" 79 | flutter_qr_reader: 80 | dependency: "direct dev" 81 | description: 82 | path: ".." 83 | relative: true 84 | source: path 85 | version: "1.0.3" 86 | flutter_test: 87 | dependency: "direct dev" 88 | description: flutter 89 | source: sdk 90 | version: "0.0.0" 91 | image: 92 | dependency: transitive 93 | description: 94 | name: image 95 | url: "https://pub.dartlang.org" 96 | source: hosted 97 | version: "2.1.4" 98 | image_picker: 99 | dependency: "direct main" 100 | description: 101 | name: image_picker 102 | url: "https://pub.dartlang.org" 103 | source: hosted 104 | version: "0.6.3+4" 105 | matcher: 106 | dependency: transitive 107 | description: 108 | name: matcher 109 | url: "https://pub.dartlang.org" 110 | source: hosted 111 | version: "0.12.6" 112 | meta: 113 | dependency: transitive 114 | description: 115 | name: meta 116 | url: "https://pub.dartlang.org" 117 | source: hosted 118 | version: "1.1.8" 119 | path: 120 | dependency: transitive 121 | description: 122 | name: path 123 | url: "https://pub.dartlang.org" 124 | source: hosted 125 | version: "1.6.4" 126 | pedantic: 127 | dependency: transitive 128 | description: 129 | name: pedantic 130 | url: "https://pub.dartlang.org" 131 | source: hosted 132 | version: "1.8.0+1" 133 | permission_handler: 134 | dependency: "direct main" 135 | description: 136 | name: permission_handler 137 | url: "https://pub.dartlang.org" 138 | source: hosted 139 | version: "3.3.0" 140 | petitparser: 141 | dependency: transitive 142 | description: 143 | name: petitparser 144 | url: "https://pub.dartlang.org" 145 | source: hosted 146 | version: "2.4.0" 147 | quiver: 148 | dependency: transitive 149 | description: 150 | name: quiver 151 | url: "https://pub.dartlang.org" 152 | source: hosted 153 | version: "2.0.5" 154 | sky_engine: 155 | dependency: transitive 156 | description: flutter 157 | source: sdk 158 | version: "0.0.99" 159 | source_span: 160 | dependency: transitive 161 | description: 162 | name: source_span 163 | url: "https://pub.dartlang.org" 164 | source: hosted 165 | version: "1.5.5" 166 | stack_trace: 167 | dependency: transitive 168 | description: 169 | name: stack_trace 170 | url: "https://pub.dartlang.org" 171 | source: hosted 172 | version: "1.9.3" 173 | stream_channel: 174 | dependency: transitive 175 | description: 176 | name: stream_channel 177 | url: "https://pub.dartlang.org" 178 | source: hosted 179 | version: "2.0.0" 180 | string_scanner: 181 | dependency: transitive 182 | description: 183 | name: string_scanner 184 | url: "https://pub.dartlang.org" 185 | source: hosted 186 | version: "1.0.5" 187 | term_glyph: 188 | dependency: transitive 189 | description: 190 | name: term_glyph 191 | url: "https://pub.dartlang.org" 192 | source: hosted 193 | version: "1.1.0" 194 | test_api: 195 | dependency: transitive 196 | description: 197 | name: test_api 198 | url: "https://pub.dartlang.org" 199 | source: hosted 200 | version: "0.2.11" 201 | typed_data: 202 | dependency: transitive 203 | description: 204 | name: typed_data 205 | url: "https://pub.dartlang.org" 206 | source: hosted 207 | version: "1.1.6" 208 | vector_math: 209 | dependency: transitive 210 | description: 211 | name: vector_math 212 | url: "https://pub.dartlang.org" 213 | source: hosted 214 | version: "2.0.8" 215 | xml: 216 | dependency: transitive 217 | description: 218 | name: xml 219 | url: "https://pub.dartlang.org" 220 | source: hosted 221 | version: "3.5.0" 222 | sdks: 223 | dart: ">=2.4.0 <3.0.0" 224 | flutter: ">=1.12.13 <2.0.0" 225 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_qr_reader_example 2 | description: Demonstrates how to use the flutter_qr_reader plugin. 3 | publish_to: 'none' 4 | 5 | environment: 6 | sdk: ">=2.2.2 <3.0.0" 7 | 8 | dependencies: 9 | flutter: 10 | sdk: flutter 11 | 12 | # The following adds the Cupertino Icons font to your application. 13 | # Use with the CupertinoIcons class for iOS style icons. 14 | cupertino_icons: ^0.1.2 15 | permission_handler: '^3.0.0' 16 | image_picker: ^0.6.0+9 17 | 18 | dev_dependencies: 19 | flutter_test: 20 | sdk: flutter 21 | 22 | flutter_qr_reader: 23 | path: ../ 24 | 25 | # For information on the generic Dart part of this file, see the 26 | # following page: https://dart.dev/tools/pub/pubspec 27 | 28 | # The following section is specific to Flutter. 29 | flutter: 30 | 31 | # The following line ensures that the Material Icons font is 32 | # included with your application, so that you can use the icons in 33 | # the material Icons class. 34 | uses-material-design: true 35 | 36 | # To add assets to your application, add an assets section, like this: 37 | # assets: 38 | # - images/a_dot_burr.jpeg 39 | # - images/a_dot_ham.jpeg 40 | 41 | # An image asset can refer to one or more resolution-specific "variants", see 42 | # https://flutter.dev/assets-and-images/#resolution-aware. 43 | 44 | # For details regarding adding assets from package dependencies, see 45 | # https://flutter.dev/assets-and-images/#from-packages 46 | 47 | # To add custom fonts to your application, add a fonts section here, 48 | # in this "flutter" section. Each entry in this list should have a 49 | # "family" key with the font family name, and a "fonts" key with a 50 | # list giving the asset and other descriptors for the font. For 51 | # example: 52 | # fonts: 53 | # - family: Schyler 54 | # fonts: 55 | # - asset: fonts/Schyler-Regular.ttf 56 | # - asset: fonts/Schyler-Italic.ttf 57 | # style: italic 58 | # - family: Trajan Pro 59 | # fonts: 60 | # - asset: fonts/TrajanPro.ttf 61 | # - asset: fonts/TrajanPro_Bold.ttf 62 | # weight: 700 63 | # 64 | # For details regarding fonts from package dependencies, 65 | # see https://flutter.dev/custom-fonts/#from-packages 66 | -------------------------------------------------------------------------------- /example/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility that Flutter provides. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:flutter_qr_reader_example/main.dart'; 12 | 13 | void main() { 14 | testWidgets('Verify Platform version', (WidgetTester tester) async { 15 | // Build our app and trigger a frame. 16 | await tester.pumpWidget(MyApp()); 17 | 18 | // Verify that platform version is retrieved. 19 | expect( 20 | find.byWidgetPredicate( 21 | (Widget widget) => widget is Text && 22 | widget.data.startsWith('Running on:'), 23 | ), 24 | findsOneWidget, 25 | ); 26 | }); 27 | } 28 | -------------------------------------------------------------------------------- /ezgif-3-7c8bfe5fd68a.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/ezgif-3-7c8bfe5fd68a.gif -------------------------------------------------------------------------------- /flutter_qr_reader.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vagrant/ 3 | .sconsign.dblite 4 | .svn/ 5 | 6 | .DS_Store 7 | *.swp 8 | profile 9 | 10 | DerivedData/ 11 | build/ 12 | GeneratedPluginRegistrant.h 13 | GeneratedPluginRegistrant.m 14 | 15 | .generated/ 16 | 17 | *.pbxuser 18 | *.mode1v3 19 | *.mode2v3 20 | *.perspectivev3 21 | 22 | !default.pbxuser 23 | !default.mode1v3 24 | !default.mode2v3 25 | !default.perspectivev3 26 | 27 | xcuserdata 28 | 29 | *.moved-aside 30 | 31 | *.pyc 32 | *sync/ 33 | Icon? 34 | .tags* 35 | 36 | /Flutter/Generated.xcconfig 37 | -------------------------------------------------------------------------------- /ios/Assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hetian9288/flutter_qr_reader/e568f90723d9715bd3496877d1b23bffd09e88e2/ios/Assets/.gitkeep -------------------------------------------------------------------------------- /ios/Classes/FlutterQrReaderPlugin.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface FlutterQrReaderPlugin : NSObject 4 | @end 5 | -------------------------------------------------------------------------------- /ios/Classes/FlutterQrReaderPlugin.m: -------------------------------------------------------------------------------- 1 | #import "FlutterQrReaderPlugin.h" 2 | #import "QrReaderViewController.h" 3 | 4 | @implementation FlutterQrReaderPlugin 5 | + (void)registerWithRegistrar:(NSObject*)registrar { 6 | // 注册原生视图 7 | QrReaderViewFactory *viewFactory = [[QrReaderViewFactory alloc] initWithRegistrar:registrar]; 8 | [registrar registerViewFactory:viewFactory withId:@"me.hetian.flutter_qr_reader.reader_view"]; 9 | 10 | FlutterMethodChannel* channel = [FlutterMethodChannel 11 | methodChannelWithName:@"me.hetian.flutter_qr_reader" 12 | binaryMessenger:[registrar messenger]]; 13 | FlutterQrReaderPlugin* instance = [[FlutterQrReaderPlugin alloc] init]; 14 | [registrar addMethodCallDelegate:instance channel:channel]; 15 | } 16 | 17 | - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { 18 | if ([@"imgQrCode" isEqualToString:call.method]) { 19 | [self scanQRCode:call result:result]; 20 | } else { 21 | result(FlutterMethodNotImplemented); 22 | } 23 | } 24 | 25 | - (void)scanQRCode:(FlutterMethodCall*)call result:(FlutterResult)result{ 26 | NSString *path = call.arguments[@"file"]; 27 | UIImage *image = [UIImage imageWithContentsOfFile:path]; 28 | CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }]; 29 | 30 | NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:image.CGImage]]; 31 | if (features.count > 0) { 32 | CIQRCodeFeature *feature = [features objectAtIndex:0]; 33 | NSString *qrData = feature.messageString; 34 | result(qrData); 35 | } else { 36 | result(NULL); 37 | } 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /ios/Classes/QrReaderViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ReReaderViewController.h 3 | // flutter_qr_reader 4 | // 5 | // Created by 王贺天 on 2019/6/7. 6 | // 7 | 8 | #import 9 | #import 10 | #import 11 | #import 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface QrReaderViewController : NSObject 15 | @end 16 | 17 | @interface QrReaderViewFactory : NSObject 18 | - (instancetype)initWithRegistrar:(NSObject*)registrar; 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /ios/Classes/QrReaderViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ReReaderViewController.m 3 | // flutter_qr_reader 4 | // 5 | // Created by 王贺天 on 2019/6/7. 6 | // 7 | 8 | #import "QrReaderViewController.h" 9 | 10 | @interface QrReaderViewController() 11 | @property (nonatomic, strong) AVCaptureSession *captureSession; 12 | @property (nonatomic, strong) AVCaptureVideoPreviewLayer *videoPreviewLayer; 13 | @end 14 | 15 | @implementation QrReaderViewController{ 16 | UIView* _qrcodeview; 17 | int64_t _viewId; 18 | FlutterMethodChannel* _channel; 19 | NSObject* _registrar; 20 | NSNumber *height; 21 | NSNumber *width; 22 | BOOL isOpenFlash; 23 | BOOL _isReading; 24 | AVCaptureDevice *captureDevice; 25 | } 26 | 27 | - (instancetype)initWithFrame:(CGRect)frame 28 | viewIdentifier:(int64_t)viewId 29 | arguments:(id _Nullable)args 30 | binaryRegistrar:(NSObject*)registrar 31 | { 32 | if ([super init]) { 33 | _registrar = registrar; 34 | _viewId = viewId; 35 | NSString *channelName = [NSString stringWithFormat:@"me.hetian.flutter_qr_reader.reader_view_%lld", viewId]; 36 | _channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:registrar.messenger]; 37 | __weak __typeof__(self) weakSelf = self; 38 | [_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { 39 | [weakSelf onMethodCall:call result:result]; 40 | }]; 41 | width = args[@"width"]; 42 | height = args[@"height"]; 43 | NSLog(@"%@,%@", width, height); 44 | _qrcodeview= [[UIView alloc] initWithFrame:CGRectMake(0, 0, width.floatValue, height.floatValue) ]; 45 | _qrcodeview.opaque = NO; 46 | _qrcodeview.backgroundColor = [UIColor blackColor]; 47 | isOpenFlash = NO; 48 | _isReading = NO; 49 | } 50 | return self; 51 | } 52 | 53 | - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result 54 | { 55 | if ([call.method isEqualToString:@"flashlight"]) { 56 | [self setFlashlight]; 57 | }else if ([call.method isEqualToString:@"startCamera"]) { 58 | [self startReading]; 59 | } else if ([call.method isEqualToString:@"stopCamera"]) { 60 | [self stopReading]; 61 | } 62 | } 63 | 64 | - (nonnull UIView *)view { 65 | return _qrcodeview; 66 | } 67 | 68 | - (BOOL)startReading { 69 | if (_isReading) return NO; 70 | _isReading = YES; 71 | NSError *error; 72 | _captureSession = [[AVCaptureSession alloc] init]; 73 | captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 74 | AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error]; 75 | if (!input) { 76 | NSLog(@"%@", [error localizedDescription]); 77 | return NO; 78 | } 79 | [_captureSession addInput:input]; 80 | AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init]; 81 | [_captureSession addOutput:captureMetadataOutput]; 82 | dispatch_queue_t dispatchQueue; 83 | dispatchQueue = dispatch_queue_create("myQueue", NULL); 84 | [captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue]; 85 | [captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeQRCode]]; 86 | _videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession]; 87 | [_videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; 88 | [_videoPreviewLayer setFrame:_qrcodeview.layer.bounds]; 89 | [_qrcodeview.layer addSublayer:_videoPreviewLayer]; 90 | [_captureSession startRunning]; 91 | return YES; 92 | } 93 | 94 | 95 | -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{ 96 | if (metadataObjects != nil && [metadataObjects count] > 0) { 97 | AVMetadataMachineReadableCodeObject *metadataObj = [metadataObjects objectAtIndex:0]; 98 | if ([[metadataObj type] isEqualToString:AVMetadataObjectTypeQRCode]) { 99 | NSMutableDictionary *dic = [[NSMutableDictionary alloc] init]; 100 | [dic setObject:[metadataObj stringValue] forKey:@"text"]; 101 | [_channel invokeMethod:@"onQRCodeRead" arguments:dic]; 102 | [self performSelectorOnMainThread:@selector(stopReading) withObject:nil waitUntilDone:NO]; 103 | _isReading = NO; 104 | } 105 | } 106 | } 107 | 108 | 109 | -(void)stopReading{ 110 | [_captureSession stopRunning]; 111 | _captureSession = nil; 112 | [_videoPreviewLayer removeFromSuperlayer]; 113 | _isReading = NO; 114 | } 115 | 116 | // 手电筒开关 117 | - (void) setFlashlight 118 | { 119 | [captureDevice lockForConfiguration:nil]; 120 | if (isOpenFlash == NO) { 121 | [captureDevice setTorchMode:AVCaptureTorchModeOn]; 122 | isOpenFlash = YES; 123 | } else { 124 | [captureDevice setTorchMode:AVCaptureTorchModeOff]; 125 | isOpenFlash = NO; 126 | } 127 | 128 | [captureDevice unlockForConfiguration]; 129 | } 130 | 131 | @end 132 | 133 | @implementation QrReaderViewFactory{ 134 | NSObject* _registrar; 135 | } 136 | - (instancetype)initWithRegistrar:(NSObject*)registrar 137 | { 138 | self = [super init]; 139 | if (self) { 140 | _registrar = registrar; 141 | } 142 | return self; 143 | } 144 | 145 | - (NSObject*)createArgsCodec { 146 | return [FlutterStandardMessageCodec sharedInstance]; 147 | } 148 | 149 | - (NSObject*)createWithFrame:(CGRect)frame 150 | viewIdentifier:(int64_t)viewId 151 | arguments:(id _Nullable)args 152 | { 153 | QrReaderViewController* viewController = [[QrReaderViewController alloc] initWithFrame:frame 154 | viewIdentifier:viewId 155 | arguments:args 156 | binaryRegistrar:_registrar]; 157 | return viewController; 158 | } 159 | @end 160 | 161 | -------------------------------------------------------------------------------- /ios/flutter_qr_reader.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 3 | # 4 | Pod::Spec.new do |s| 5 | s.name = 'flutter_qr_reader' 6 | s.version = '0.0.1' 7 | s.summary = 'QR code (scan code / picture) recognition (AndroidView/UiKitView)' 8 | s.description = <<-DESC 9 | QR code (scan code / picture) recognition (AndroidView/UiKitView) 10 | DESC 11 | s.homepage = 'http://example.com' 12 | s.license = { :file => '../LICENSE' } 13 | s.author = { 'Your Company' => 'email@example.com' } 14 | s.source = { :path => '.' } 15 | s.source_files = 'Classes/**/*' 16 | s.public_header_files = 'Classes/**/*.h' 17 | s.dependency 'Flutter' 18 | 19 | s.ios.deployment_target = '8.0' 20 | end 21 | 22 | -------------------------------------------------------------------------------- /lib/flutter_qr_reader.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:io'; 3 | import 'dart:ui'; 4 | 5 | import 'package:flutter/foundation.dart'; 6 | import 'package:flutter/gestures.dart'; 7 | import 'package:flutter/services.dart'; 8 | import 'package:flutter/widgets.dart'; 9 | 10 | class FlutterQrReader { 11 | static const MethodChannel _channel = const MethodChannel('me.hetian.flutter_qr_reader'); 12 | 13 | static Future imgScan(File file) async { 14 | if (file?.existsSync() == false) { 15 | return null; 16 | } 17 | try { 18 | final rest = await _channel.invokeMethod("imgQrCode", {"file": file.path}); 19 | return rest; 20 | } catch (e) { 21 | print(e); 22 | return null; 23 | } 24 | } 25 | } 26 | 27 | class QrReaderView extends StatefulWidget { 28 | final Function(QrReaderViewController) callback; 29 | 30 | final int autoFocusIntervalInMs; 31 | final bool torchEnabled; 32 | final double width; 33 | final double height; 34 | 35 | QrReaderView({ 36 | Key key, 37 | this.width, 38 | this.height, 39 | this.callback, 40 | this.autoFocusIntervalInMs = 500, 41 | this.torchEnabled = false, 42 | }) : super(key: key); 43 | 44 | @override 45 | _QrReaderViewState createState() => new _QrReaderViewState(); 46 | } 47 | 48 | class _QrReaderViewState extends State { 49 | @override 50 | void initState() { 51 | super.initState(); 52 | } 53 | 54 | @override 55 | Widget build(BuildContext context) { 56 | if (defaultTargetPlatform == TargetPlatform.android) { 57 | return AndroidView( 58 | viewType: "me.hetian.flutter_qr_reader.reader_view", 59 | creationParams: { 60 | "width": (widget.width * window.devicePixelRatio).floor(), 61 | "height": (widget.height * window.devicePixelRatio).floor(), 62 | "extra_focus_interval": widget.autoFocusIntervalInMs, 63 | "extra_torch_enabled": widget.torchEnabled, 64 | }, 65 | creationParamsCodec: const StandardMessageCodec(), 66 | onPlatformViewCreated: _onPlatformViewCreated, 67 | gestureRecognizers: >[ 68 | new Factory(() => new EagerGestureRecognizer()), 69 | ].toSet(), 70 | ); 71 | } else if (defaultTargetPlatform == TargetPlatform.iOS) { 72 | return UiKitView( 73 | viewType: "me.hetian.flutter_qr_reader.reader_view", 74 | creationParams: { 75 | "width": widget.width, 76 | "height": widget.height, 77 | "extra_focus_interval": widget.autoFocusIntervalInMs, 78 | "extra_torch_enabled": widget.torchEnabled, 79 | }, 80 | creationParamsCodec: const StandardMessageCodec(), 81 | onPlatformViewCreated: _onPlatformViewCreated, 82 | gestureRecognizers: >[ 83 | new Factory(() => new EagerGestureRecognizer()), 84 | ].toSet(), 85 | ); 86 | } else { 87 | return Text('平台暂不支持'); 88 | } 89 | } 90 | 91 | void _onPlatformViewCreated(int id) { 92 | widget.callback(QrReaderViewController(id)); 93 | } 94 | 95 | @override 96 | void dispose() { 97 | super.dispose(); 98 | } 99 | } 100 | 101 | typedef ReadChangeBack = void Function(String, List); 102 | 103 | class QrReaderViewController { 104 | final int id; 105 | final MethodChannel _channel; 106 | QrReaderViewController(this.id) : _channel = MethodChannel('me.hetian.flutter_qr_reader.reader_view_$id') { 107 | _channel.setMethodCallHandler(_handleMessages); 108 | } 109 | ReadChangeBack onQrBack; 110 | 111 | Future _handleMessages(MethodCall call) async { 112 | switch (call.method) { 113 | case "onQRCodeRead": 114 | final points = List(); 115 | if (call.arguments.containsKey("points")) { 116 | final pointsStrs = call.arguments["points"]; 117 | for (String point in pointsStrs) { 118 | final a = point.split(","); 119 | points.add(Offset(double.tryParse(a.first), double.tryParse(a.last))); 120 | } 121 | } 122 | 123 | this.onQrBack(call.arguments["text"], points); 124 | break; 125 | } 126 | } 127 | 128 | // 打开手电筒 129 | Future setFlashlight() async { 130 | return _channel.invokeMethod("flashlight"); 131 | } 132 | 133 | // 开始扫码 134 | Future startCamera(ReadChangeBack onQrBack) async { 135 | this.onQrBack = onQrBack; 136 | return _channel.invokeMethod("startCamera"); 137 | } 138 | 139 | // 结束扫码 140 | Future stopCamera() async { 141 | return _channel.invokeMethod("stopCamera"); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /lib/qrcode_reader_view.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'flutter_qr_reader.dart'; 5 | import 'package:image_picker/image_picker.dart'; 6 | 7 | /// 使用前需已经获取相关权限 8 | /// Relevant privileges must be obtained before use 9 | class QrcodeReaderView extends StatefulWidget { 10 | final Widget headerWidget; 11 | final Future Function(String) onScan; 12 | final double scanBoxRatio; 13 | final Color boxLineColor; 14 | final Widget helpWidget; 15 | QrcodeReaderView({ 16 | Key key, 17 | @required this.onScan, 18 | this.headerWidget, 19 | this.boxLineColor = Colors.cyanAccent, 20 | this.helpWidget, 21 | this.scanBoxRatio = 0.85, 22 | }) : super(key: key); 23 | 24 | @override 25 | QrcodeReaderViewState createState() => new QrcodeReaderViewState(); 26 | } 27 | 28 | /// 扫码后的后续操作 29 | /// ```dart 30 | /// GlobalKey qrViewKey = GlobalKey(); 31 | /// qrViewKey.currentState.startScan(); 32 | /// ``` 33 | class QrcodeReaderViewState extends State 34 | with TickerProviderStateMixin { 35 | QrReaderViewController _controller; 36 | AnimationController _animationController; 37 | bool openFlashlight; 38 | Timer _timer; 39 | @override 40 | void initState() { 41 | super.initState(); 42 | openFlashlight = false; 43 | _initAnimation(); 44 | } 45 | 46 | void _initAnimation() { 47 | setState(() { 48 | _animationController = AnimationController( 49 | vsync: this, duration: Duration(milliseconds: 1000)); 50 | }); 51 | _animationController 52 | ..addListener(_upState) 53 | ..addStatusListener((state) { 54 | if (state == AnimationStatus.completed) { 55 | _timer = Timer(Duration(seconds: 1), () { 56 | _animationController?.reverse(from: 1.0); 57 | }); 58 | } else if (state == AnimationStatus.dismissed) { 59 | _timer = Timer(Duration(seconds: 1), () { 60 | _animationController?.forward(from: 0.0); 61 | }); 62 | } 63 | }); 64 | _animationController.forward(from: 0.0); 65 | } 66 | 67 | void _clearAnimation() { 68 | _timer?.cancel(); 69 | if (_animationController != null) { 70 | _animationController?.dispose(); 71 | _animationController = null; 72 | } 73 | } 74 | 75 | void _upState() { 76 | setState(() {}); 77 | } 78 | 79 | void _onCreateController(QrReaderViewController controller) async { 80 | _controller = controller; 81 | _controller.startCamera(_onQrBack); 82 | } 83 | 84 | bool isScan = false; 85 | Future _onQrBack(data, _) async { 86 | if (isScan == true) return; 87 | isScan = true; 88 | stopScan(); 89 | await widget.onScan(data); 90 | } 91 | 92 | void startScan() { 93 | isScan = false; 94 | _controller.startCamera(_onQrBack); 95 | _initAnimation(); 96 | } 97 | 98 | void stopScan() { 99 | _clearAnimation(); 100 | _controller.stopCamera(); 101 | } 102 | 103 | Future setFlashlight() async { 104 | openFlashlight = await _controller.setFlashlight(); 105 | setState(() {}); 106 | return openFlashlight; 107 | } 108 | 109 | Future _scanImage() async { 110 | stopScan(); 111 | var image = await ImagePicker.pickImage(source: ImageSource.gallery); 112 | if (image == null) { 113 | startScan(); 114 | return; 115 | } 116 | final rest = await FlutterQrReader.imgScan(image); 117 | await widget.onScan(rest); 118 | startScan(); 119 | } 120 | 121 | @override 122 | Widget build(BuildContext context) { 123 | final flashOpen = Image.asset( 124 | "assets/tool_flashlight_open.png", 125 | package: "flutter_qr_reader", 126 | width: 35, 127 | height: 35, 128 | color: Colors.white, 129 | ); 130 | final flashClose = Image.asset( 131 | "assets/tool_flashlight_close.png", 132 | package: "flutter_qr_reader", 133 | width: 35, 134 | height: 35, 135 | color: Colors.white, 136 | ); 137 | return Material( 138 | color: Colors.black, 139 | child: LayoutBuilder(builder: (context, constraints) { 140 | final qrScanSize = constraints.maxWidth * widget.scanBoxRatio; 141 | final mediaQuery = MediaQuery.of(context); 142 | if (constraints.maxHeight < qrScanSize * 1.5) { 143 | print("建议高度与扫码区域高度比大于1.5"); 144 | } 145 | return Stack( 146 | children: [ 147 | SizedBox( 148 | width: constraints.maxWidth, 149 | height: constraints.maxHeight, 150 | child: QrReaderView( 151 | width: constraints.maxWidth, 152 | height: constraints.maxHeight, 153 | callback: _onCreateController, 154 | ), 155 | ), 156 | if (widget.headerWidget != null) widget.headerWidget, 157 | Positioned( 158 | left: (constraints.maxWidth - qrScanSize) / 2, 159 | top: (constraints.maxHeight - qrScanSize) * 0.333333, 160 | child: CustomPaint( 161 | painter: QrScanBoxPainter( 162 | boxLineColor: widget.boxLineColor, 163 | animationValue: _animationController?.value ?? 0, 164 | isForward: 165 | _animationController?.status == AnimationStatus.forward, 166 | ), 167 | child: SizedBox( 168 | width: qrScanSize, 169 | height: qrScanSize, 170 | ), 171 | ), 172 | ), 173 | Positioned( 174 | top: (constraints.maxHeight - qrScanSize) * 0.333333 + 175 | qrScanSize + 176 | 24, 177 | width: constraints.maxWidth, 178 | child: Align( 179 | alignment: Alignment.center, 180 | child: DefaultTextStyle( 181 | style: TextStyle(color: Colors.white), 182 | child: widget.helpWidget ?? Text("请将二维码置于方框中"), 183 | ), 184 | ), 185 | ), 186 | Positioned( 187 | top: (constraints.maxHeight - qrScanSize) * 0.333333 + 188 | qrScanSize - 189 | 12 - 190 | 35, 191 | width: constraints.maxWidth, 192 | child: Align( 193 | alignment: Alignment.center, 194 | child: GestureDetector( 195 | behavior: HitTestBehavior.translucent, 196 | onTap: setFlashlight, 197 | child: openFlashlight ? flashOpen : flashClose, 198 | ), 199 | ), 200 | ), 201 | Positioned( 202 | width: constraints.maxWidth, 203 | bottom: constraints.maxHeight == mediaQuery.size.height 204 | ? 12 + mediaQuery.padding.top 205 | : 12, 206 | child: Row( 207 | crossAxisAlignment: CrossAxisAlignment.center, 208 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, 209 | children: [ 210 | GestureDetector( 211 | behavior: HitTestBehavior.translucent, 212 | onTap: _scanImage, 213 | child: Container( 214 | width: 45, 215 | height: 45, 216 | alignment: Alignment.center, 217 | child: Image.asset( 218 | "assets/tool_img.png", 219 | package: "flutter_qr_reader", 220 | width: 25, 221 | height: 25, 222 | color: Colors.white54, 223 | ), 224 | ), 225 | ), 226 | Container( 227 | width: 80, 228 | height: 80, 229 | decoration: BoxDecoration( 230 | borderRadius: BorderRadius.all(Radius.circular(40)), 231 | border: Border.all(color: Colors.white30, width: 12), 232 | ), 233 | alignment: Alignment.center, 234 | child: Image.asset( 235 | "assets/tool_qrcode.png", 236 | package: "flutter_qr_reader", 237 | width: 35, 238 | height: 35, 239 | color: Colors.white54, 240 | ), 241 | ), 242 | SizedBox(width: 45, height: 45), 243 | ], 244 | ), 245 | ) 246 | ], 247 | ); 248 | }), 249 | ); 250 | } 251 | 252 | @override 253 | void dispose() { 254 | _clearAnimation(); 255 | super.dispose(); 256 | } 257 | } 258 | 259 | class QrScanBoxPainter extends CustomPainter { 260 | final double animationValue; 261 | final bool isForward; 262 | final Color boxLineColor; 263 | 264 | QrScanBoxPainter( 265 | {@required this.animationValue, 266 | @required this.isForward, 267 | this.boxLineColor}) 268 | : assert(animationValue != null), 269 | assert(isForward != null); 270 | 271 | @override 272 | void paint(Canvas canvas, Size size) { 273 | final borderRadius = BorderRadius.all(Radius.circular(12)).toRRect( 274 | Rect.fromLTWH(0, 0, size.width, size.height), 275 | ); 276 | canvas.drawRRect( 277 | borderRadius, 278 | Paint() 279 | ..color = Colors.white54 280 | ..style = PaintingStyle.stroke 281 | ..strokeWidth = 1, 282 | ); 283 | final borderPaint = Paint() 284 | ..color = Colors.white 285 | ..style = PaintingStyle.stroke 286 | ..strokeWidth = 2; 287 | final path = new Path(); 288 | // leftTop 289 | path.moveTo(0, 50); 290 | path.lineTo(0, 12); 291 | path.quadraticBezierTo(0, 0, 12, 0); 292 | path.lineTo(50, 0); 293 | // rightTop 294 | path.moveTo(size.width - 50, 0); 295 | path.lineTo(size.width - 12, 0); 296 | path.quadraticBezierTo(size.width, 0, size.width, 12); 297 | path.lineTo(size.width, 50); 298 | // rightBottom 299 | path.moveTo(size.width, size.height - 50); 300 | path.lineTo(size.width, size.height - 12); 301 | path.quadraticBezierTo( 302 | size.width, size.height, size.width - 12, size.height); 303 | path.lineTo(size.width - 50, size.height); 304 | // leftBottom 305 | path.moveTo(50, size.height); 306 | path.lineTo(12, size.height); 307 | path.quadraticBezierTo(0, size.height, 0, size.height - 12); 308 | path.lineTo(0, size.height - 50); 309 | 310 | canvas.drawPath(path, borderPaint); 311 | 312 | canvas.clipRRect( 313 | BorderRadius.all(Radius.circular(12)).toRRect(Offset.zero & size)); 314 | 315 | // 绘制横向网格 316 | final linePaint = Paint(); 317 | final lineSize = size.height * 0.45; 318 | final leftPress = (size.height + lineSize) * animationValue - lineSize; 319 | linePaint.style = PaintingStyle.stroke; 320 | linePaint.shader = LinearGradient( 321 | colors: [Colors.transparent, boxLineColor], 322 | begin: isForward ? Alignment.topCenter : Alignment(0.0, 2.0), 323 | end: isForward ? Alignment(0.0, 0.5) : Alignment.topCenter, 324 | ).createShader(Rect.fromLTWH(0, leftPress, size.width, lineSize)); 325 | for (int i = 0; i < size.height / 5; i++) { 326 | canvas.drawLine( 327 | Offset( 328 | i * 5.0, 329 | leftPress, 330 | ), 331 | Offset(i * 5.0, leftPress + lineSize), 332 | linePaint, 333 | ); 334 | } 335 | for (int i = 0; i < lineSize / 5; i++) { 336 | canvas.drawLine( 337 | Offset(0, leftPress + i * 5.0), 338 | Offset( 339 | size.width, 340 | leftPress + i * 5.0, 341 | ), 342 | linePaint, 343 | ); 344 | } 345 | } 346 | 347 | @override 348 | bool shouldRepaint(QrScanBoxPainter oldDelegate) => 349 | animationValue != oldDelegate.animationValue; 350 | 351 | @override 352 | bool shouldRebuildSemantics(QrScanBoxPainter oldDelegate) => 353 | animationValue != oldDelegate.animationValue; 354 | } 355 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | archive: 5 | dependency: transitive 6 | description: 7 | name: archive 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.0.11" 11 | args: 12 | dependency: transitive 13 | description: 14 | name: args 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "1.5.2" 18 | async: 19 | dependency: transitive 20 | description: 21 | name: async 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.4.0" 25 | boolean_selector: 26 | dependency: transitive 27 | description: 28 | name: boolean_selector 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "1.0.5" 32 | charcode: 33 | dependency: transitive 34 | description: 35 | name: charcode 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.1.2" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.14.11" 46 | convert: 47 | dependency: transitive 48 | description: 49 | name: convert 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "2.1.1" 53 | crypto: 54 | dependency: transitive 55 | description: 56 | name: crypto 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "2.1.3" 60 | flutter: 61 | dependency: "direct main" 62 | description: flutter 63 | source: sdk 64 | version: "0.0.0" 65 | flutter_plugin_android_lifecycle: 66 | dependency: transitive 67 | description: 68 | name: flutter_plugin_android_lifecycle 69 | url: "https://pub.dartlang.org" 70 | source: hosted 71 | version: "1.0.6" 72 | flutter_test: 73 | dependency: "direct dev" 74 | description: flutter 75 | source: sdk 76 | version: "0.0.0" 77 | image: 78 | dependency: transitive 79 | description: 80 | name: image 81 | url: "https://pub.dartlang.org" 82 | source: hosted 83 | version: "2.1.4" 84 | image_picker: 85 | dependency: "direct main" 86 | description: 87 | name: image_picker 88 | url: "https://pub.dartlang.org" 89 | source: hosted 90 | version: "0.6.3+4" 91 | matcher: 92 | dependency: transitive 93 | description: 94 | name: matcher 95 | url: "https://pub.dartlang.org" 96 | source: hosted 97 | version: "0.12.6" 98 | meta: 99 | dependency: transitive 100 | description: 101 | name: meta 102 | url: "https://pub.dartlang.org" 103 | source: hosted 104 | version: "1.1.8" 105 | path: 106 | dependency: transitive 107 | description: 108 | name: path 109 | url: "https://pub.dartlang.org" 110 | source: hosted 111 | version: "1.6.4" 112 | pedantic: 113 | dependency: transitive 114 | description: 115 | name: pedantic 116 | url: "https://pub.dartlang.org" 117 | source: hosted 118 | version: "1.8.0+1" 119 | petitparser: 120 | dependency: transitive 121 | description: 122 | name: petitparser 123 | url: "https://pub.dartlang.org" 124 | source: hosted 125 | version: "2.4.0" 126 | quiver: 127 | dependency: transitive 128 | description: 129 | name: quiver 130 | url: "https://pub.dartlang.org" 131 | source: hosted 132 | version: "2.0.5" 133 | sky_engine: 134 | dependency: transitive 135 | description: flutter 136 | source: sdk 137 | version: "0.0.99" 138 | source_span: 139 | dependency: transitive 140 | description: 141 | name: source_span 142 | url: "https://pub.dartlang.org" 143 | source: hosted 144 | version: "1.5.5" 145 | stack_trace: 146 | dependency: transitive 147 | description: 148 | name: stack_trace 149 | url: "https://pub.dartlang.org" 150 | source: hosted 151 | version: "1.9.3" 152 | stream_channel: 153 | dependency: transitive 154 | description: 155 | name: stream_channel 156 | url: "https://pub.dartlang.org" 157 | source: hosted 158 | version: "2.0.0" 159 | string_scanner: 160 | dependency: transitive 161 | description: 162 | name: string_scanner 163 | url: "https://pub.dartlang.org" 164 | source: hosted 165 | version: "1.0.5" 166 | term_glyph: 167 | dependency: transitive 168 | description: 169 | name: term_glyph 170 | url: "https://pub.dartlang.org" 171 | source: hosted 172 | version: "1.1.0" 173 | test_api: 174 | dependency: transitive 175 | description: 176 | name: test_api 177 | url: "https://pub.dartlang.org" 178 | source: hosted 179 | version: "0.2.11" 180 | typed_data: 181 | dependency: transitive 182 | description: 183 | name: typed_data 184 | url: "https://pub.dartlang.org" 185 | source: hosted 186 | version: "1.1.6" 187 | vector_math: 188 | dependency: transitive 189 | description: 190 | name: vector_math 191 | url: "https://pub.dartlang.org" 192 | source: hosted 193 | version: "2.0.8" 194 | xml: 195 | dependency: transitive 196 | description: 197 | name: xml 198 | url: "https://pub.dartlang.org" 199 | source: hosted 200 | version: "3.5.0" 201 | sdks: 202 | dart: ">=2.4.0 <3.0.0" 203 | flutter: ">=1.12.13 <2.0.0" 204 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_qr_reader 2 | description: QR code (scan QRCode and picture) recognition (AndroidView/UiKitView) 3 | version: 1.0.3 4 | author: 王贺天 5 | homepage: https://github.com/hetian9288/flutter_qr_reader 6 | 7 | environment: 8 | sdk: ">=2.2.2 <3.0.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | image_picker: ^0.6.0+9 14 | 15 | dev_dependencies: 16 | flutter_test: 17 | sdk: flutter 18 | 19 | # For information on the generic Dart part of this file, see the 20 | # following page: https://dart.dev/tools/pub/pubspec 21 | 22 | # The following section is specific to Flutter. 23 | flutter: 24 | # This section identifies this Flutter project as a plugin project. 25 | # The androidPackage and pluginClass identifiers should not ordinarily 26 | # be modified. They are used by the tooling to maintain consistency when 27 | # adding or updating assets for this project. 28 | plugin: 29 | androidPackage: me.hetian.flutter_qr_reader 30 | pluginClass: FlutterQrReaderPlugin 31 | 32 | # To add assets to your plugin package, add an assets section, like this: 33 | # assets: 34 | # - images/a_dot_burr.jpeg 35 | # - images/a_dot_ham.jpeg 36 | assets: 37 | - assets/tool_img.png 38 | - assets/tool_qrcode.png 39 | - assets/tool_flashlight_close.png 40 | - assets/tool_flashlight_open.png 41 | # 42 | # For details regarding assets in packages, see 43 | # https://flutter.dev/assets-and-images/#from-packages 44 | # 45 | # An image asset can refer to one or more resolution-specific "variants", see 46 | # https://flutter.dev/assets-and-images/#resolution-aware. 47 | 48 | # To add custom fonts to your plugin package, add a fonts section here, 49 | # in this "flutter" section. Each entry in this list should have a 50 | # "family" key with the font family name, and a "fonts" key with a 51 | # list giving the asset and other descriptors for the font. For 52 | # example: 53 | # fonts: 54 | # - family: Schyler 55 | # fonts: 56 | # - asset: fonts/Schyler-Regular.ttf 57 | # - asset: fonts/Schyler-Italic.ttf 58 | # style: italic 59 | # - family: Trajan Pro 60 | # fonts: 61 | # - asset: fonts/TrajanPro.ttf 62 | # - asset: fonts/TrajanPro_Bold.ttf 63 | # weight: 700 64 | # 65 | # For details regarding fonts in packages, see 66 | # https://flutter.dev/custom-fonts/#from-packages 67 | -------------------------------------------------------------------------------- /test/flutter_qr_reader_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | void main() { 5 | const MethodChannel channel = MethodChannel('flutter_qr_reader'); 6 | 7 | setUp(() { 8 | channel.setMockMethodCallHandler((MethodCall methodCall) async { 9 | return '42'; 10 | }); 11 | }); 12 | 13 | tearDown(() { 14 | channel.setMockMethodCallHandler(null); 15 | }); 16 | 17 | test('getPlatformVersion', () async { 18 | }); 19 | } 20 | --------------------------------------------------------------------------------