zhaoyadi 4 anos atrás
pai
commit
0625935079

+ 1 - 1
example/.flutter-plugins-dependencies

@@ -1 +1 @@
-{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\image_picker-0.6.7+11\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\permission_handler-3.3.0\\\\","dependencies":[]},{"name":"r_scan","path":"D:\\\\code\\\\r_scan\\\\","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\flutter_plugin_android_lifecycle-1.0.11\\\\","dependencies":[]},{"name":"image_picker","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\image_picker-0.6.7+11\\\\","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\permission_handler-3.3.0\\\\","dependencies":[]},{"name":"r_scan","path":"D:\\\\code\\\\r_scan\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","dependencies":[]},{"name":"r_scan","dependencies":[]}],"date_created":"2021-03-09 19:36:43.389007","version":"2.0.1"}
+{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\image_picker-0.7.4\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\permission_handler-6.1.1\\\\","dependencies":[]},{"name":"r_scan","path":"D:\\\\code\\\\r_scan\\\\","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\flutter_plugin_android_lifecycle-2.0.1\\\\","dependencies":[]},{"name":"image_picker","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\image_picker-0.7.4\\\\","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"permission_handler","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\permission_handler-6.1.1\\\\","dependencies":[]},{"name":"r_scan","path":"D:\\\\code\\\\r_scan\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"image_picker_for_web","path":"C:\\\\Users\\\\zhaoyadi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\image_picker_for_web-2.0.0\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle","image_picker_for_web"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"r_scan","dependencies":[]}],"date_created":"2021-04-01 12:11:27.818057","version":"2.0.3"}

+ 15 - 22
example/lib/main.dart

@@ -34,7 +34,7 @@ class MyPage extends StatefulWidget {
 }
 
 class _MyPageState extends State<MyPage> {
-  RScanResult result;
+  RScanResult? result;
 
   @override
   Widget build(BuildContext context) {
@@ -46,17 +46,12 @@ class _MyPageState extends State<MyPage> {
         mainAxisAlignment: MainAxisAlignment.center,
         crossAxisAlignment: CrossAxisAlignment.center,
         children: <Widget>[
-          Center(
-              child: Text(result == null
-                  ? '点击下方按钮开始扫码'
-                  : '扫码结果${result.toString().split(',').join('\n')}')),
+          Center(child: Text(result == null ? '点击下方按钮开始扫码' : '扫码结果${result.toString().split(',').join('\n')}')),
           Center(
             child: FlatButton(
               onPressed: () async {
-                final result = await Navigator.of(context).push(
-                    MaterialPageRoute(
-                        builder: (BuildContext context) =>
-                            RScanCameraDialog()));
+                final result = await Navigator.of(context)
+                    .push(MaterialPageRoute(builder: (BuildContext context) => RScanCameraDialog()));
                 setState(() {
                   this.result = result;
                 });
@@ -67,9 +62,8 @@ class _MyPageState extends State<MyPage> {
           Center(
             child: FlatButton(
               onPressed: () async {
-                final result = await Navigator.of(context).push(
-                    MaterialPageRoute(
-                        builder: (BuildContext context) => RScanDialog()));
+                final result = await Navigator.of(context)
+                    .push(MaterialPageRoute(builder: (BuildContext context) => RScanDialog()));
                 setState(() {
                   this.result = result;
                 });
@@ -81,8 +75,7 @@ class _MyPageState extends State<MyPage> {
             child: FlatButton(
               onPressed: () async {
                 if (await canReadStorage()) {
-                  var image =
-                      await ImagePicker.pickImage(source: ImageSource.gallery);
+                  var image = await ImagePicker().getImage(source: ImageSource.gallery);
                   if (image != null) {
                     final result = await RScan.scanImagePath(image.path);
                     setState(() {
@@ -97,8 +90,8 @@ class _MyPageState extends State<MyPage> {
           Center(
             child: FlatButton(
               onPressed: () async {
-                final result = await RScan.scanImageUrl(
-                    "https://s.cn.bing.net/th?id=OJ.5F0gxqWmxskS0Q&w=75&h=75&pid=MSNJVFeeds");
+                final result =
+                    await RScan.scanImageUrl("https://s.cn.bing.net/th?id=OJ.5F0gxqWmxskS0Q&w=75&h=75&pid=MSNJVFeeds");
                 setState(() {
                   this.result = result;
                 });
@@ -110,8 +103,7 @@ class _MyPageState extends State<MyPage> {
             child: FlatButton(
               onPressed: () async {
                 ByteData data = await rootBundle.load('images/qrCode.png');
-                final result =
-                    await RScan.scanImageMemory(data.buffer.asUint8List());
+                final result = await RScan.scanImageMemory(data.buffer.asUint8List());
                 setState(() {
                   this.result = result;
                 });
@@ -126,11 +118,12 @@ class _MyPageState extends State<MyPage> {
 
   Future<bool> canReadStorage() async {
     if (Platform.isIOS) return true;
-    var status = await PermissionHandler()
-        .checkPermissionStatus(PermissionGroup.storage);
+    var status = await Permission.storage.status;
+
+    // var status = await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
     if (status != PermissionStatus.granted) {
-      var future = await PermissionHandler()
-          .requestPermissions([PermissionGroup.storage]);
+      var future = await [Permission.storage].request();
+
       for (final item in future.entries) {
         if (item.value != PermissionStatus.granted) {
           return false;

+ 17 - 18
example/lib/scan_camera_dialog.dart

@@ -3,7 +3,7 @@ import 'package:permission_handler/permission_handler.dart';
 import 'package:r_scan_example/scan_dialog.dart';
 import 'package:r_scan/src/r_scan_camera.dart';
 
-List<RScanCameraDescription> rScanCameras;
+List<RScanCameraDescription>? rScanCameras;
 
 class RScanCameraDialog extends StatefulWidget {
   @override
@@ -11,29 +11,29 @@ class RScanCameraDialog extends StatefulWidget {
 }
 
 class _RScanCameraDialogState extends State<RScanCameraDialog> {
-  RScanCameraController _controller;
+  late RScanCameraController _controller;
   bool isFirst = true;
 
   void initCamera() async {
-    if (rScanCameras == null || rScanCameras.length == 0) {
-      final result = await PermissionHandler()
-          .checkPermissionStatus(PermissionGroup.camera);
-      if (result == PermissionStatus.granted) {
+    if (rScanCameras == null || rScanCameras!.length == 0) {
+      final status = await Permission.camera.status;
+      // final result = await Permission.checkPermissionStatus(PermissionGroup.camera);
+      if (status == PermissionStatus.granted) {
         rScanCameras = await availableRScanCameras();
-        print('返回可用的相机:${rScanCameras.join('\n')}');
+        print('返回可用的相机:${rScanCameras!.join('\n')}');
       } else {
-        final resultMap = await PermissionHandler()
-            .requestPermissions([PermissionGroup.camera]);
-        if (resultMap[PermissionGroup.camera] == PermissionStatus.granted) {
+        final result = await [Permission.camera].request();
+
+        // final resultMap = await PermissionHandler().requestPermissions([PermissionGroup.camera]);
+        if (result[Permission.camera] == PermissionStatus.granted) {
           rScanCameras = await availableRScanCameras();
         } else {
           print('相机权限被拒绝,无法使用');
         }
       }
     }
-    if (rScanCameras != null && rScanCameras.length > 0) {
-      _controller = RScanCameraController(
-          rScanCameras[0], RScanCameraResolutionPreset.high)
+    if (rScanCameras != null && rScanCameras!.length > 0) {
+      _controller = RScanCameraController(rScanCameras![0], RScanCameraResolutionPreset.high)
         ..addListener(() {
           final result = _controller.result;
           if (result != null) {
@@ -66,7 +66,7 @@ class _RScanCameraDialogState extends State<RScanCameraDialog> {
 
   @override
   Widget build(BuildContext context) {
-    if (rScanCameras == null || rScanCameras.length == 0) {
+    if (rScanCameras == null || rScanCameras!.length == 0) {
       return Scaffold(
         body: Container(
           alignment: Alignment.center,
@@ -109,14 +109,13 @@ class _RScanCameraDialogState extends State<RScanCameraDialog> {
   Widget _buildFlashBtn(BuildContext context, AsyncSnapshot<bool> snapshot) {
     return snapshot.hasData
         ? Padding(
-            padding: EdgeInsets.only(
-                bottom: 24 + MediaQuery.of(context).padding.bottom),
+            padding: EdgeInsets.only(bottom: 24 + MediaQuery.of(context).padding.bottom),
             child: IconButton(
-                icon: Icon(snapshot.data ? Icons.flash_on : Icons.flash_off),
+                icon: Icon(snapshot.data! ? Icons.flash_on : Icons.flash_off),
                 color: Colors.white,
                 iconSize: 46,
                 onPressed: () {
-                  if (snapshot.data) {
+                  if (snapshot.data!) {
                     _controller.setFlashMode(false);
                   } else {
                     _controller.setFlashMode(true);

+ 26 - 31
example/lib/scan_dialog.dart

@@ -8,7 +8,7 @@ class RScanDialog extends StatefulWidget {
 }
 
 class _RScanDialogState extends State<RScanDialog> {
-  RScanController _controller;
+  late RScanController _controller;
 
   @override
   void initState() {
@@ -71,11 +71,11 @@ class _RScanDialogState extends State<RScanDialog> {
   }
 
   Future<bool> canOpenCameraView() async {
-    var status =
-        await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
+    var status = await Permission.camera.status;
+    // var status = await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
     if (status != PermissionStatus.granted) {
-      var future = await PermissionHandler()
-          .requestPermissions([PermissionGroup.camera]);
+      var future = await [Permission.camera].request();
+      // var future = await PermissionHandler().requestPermissions([PermissionGroup.camera]);
       for (final item in future.entries) {
         if (item.value != PermissionStatus.granted) {
           return false;
@@ -90,14 +90,13 @@ class _RScanDialogState extends State<RScanDialog> {
   Widget _buildFlashBtn(BuildContext context, AsyncSnapshot<bool> snapshot) {
     return snapshot.hasData
         ? Padding(
-            padding: EdgeInsets.only(
-                bottom: 24 + MediaQuery.of(context).padding.bottom),
+            padding: EdgeInsets.only(bottom: 24 + MediaQuery.of(context).padding.bottom),
             child: IconButton(
-                icon: Icon(snapshot.data ? Icons.flash_on : Icons.flash_off),
+                icon: Icon(snapshot.data! ? Icons.flash_on : Icons.flash_off),
                 color: Colors.white,
                 iconSize: 46,
                 onPressed: () {
-                  if (snapshot.data) {
+                  if (snapshot.data!) {
                     _controller.setFlashMode(false);
                   } else {
                     _controller.setFlashMode(true);
@@ -112,21 +111,19 @@ class _RScanDialogState extends State<RScanDialog> {
 class ScanImageView extends StatefulWidget {
   final Widget child;
 
-  const ScanImageView({Key key, this.child}) : super(key: key);
+  const ScanImageView({Key? key, required this.child}) : super(key: key);
 
   @override
   _ScanImageViewState createState() => _ScanImageViewState();
 }
 
-class _ScanImageViewState extends State<ScanImageView>
-    with TickerProviderStateMixin {
-  AnimationController controller;
+class _ScanImageViewState extends State<ScanImageView> with TickerProviderStateMixin {
+  late AnimationController controller;
 
   @override
   void initState() {
     super.initState();
-    controller = AnimationController(
-        vsync: this, duration: Duration(milliseconds: 1000));
+    controller = AnimationController(vsync: this, duration: Duration(milliseconds: 1000));
     controller.repeat(reverse: true);
   }
 
@@ -140,9 +137,8 @@ class _ScanImageViewState extends State<ScanImageView>
   Widget build(BuildContext context) {
     return AnimatedBuilder(
         animation: controller,
-        builder: (BuildContext context, Widget child) => CustomPaint(
-              foregroundPainter:
-                  _ScanPainter(controller.value, Colors.white, Colors.green),
+        builder: (BuildContext context, Widget? child) => CustomPaint(
+              foregroundPainter: _ScanPainter(controller.value, Colors.white, Colors.green),
               child: widget.child,
               willChange: true,
             ));
@@ -156,7 +152,7 @@ class _ScanPainter extends CustomPainter {
 
   _ScanPainter(this.value, this.borderColor, this.scanColor);
 
-  Paint _paint;
+  Paint? _paint;
 
   @override
   void paint(Canvas canvas, Size size) {
@@ -173,39 +169,38 @@ class _ScanPainter extends CustomPainter {
     double top = boxHeight;
     double bottom = boxHeight * 2;
     double right = left + boxWidth;
-    _paint.color = borderColor;
+    _paint!.color = borderColor;
     final rect = Rect.fromLTWH(left, top, boxWidth, boxHeight);
-    canvas.drawRect(rect, _paint);
+    canvas.drawRect(rect, _paint!);
 
-    _paint.strokeWidth = 3;
+    _paint!.strokeWidth = 3;
 
     Path path1 = Path()
       ..moveTo(left, top + 10)
       ..lineTo(left, top)
       ..lineTo(left + 10, top);
-    canvas.drawPath(path1, _paint);
+    canvas.drawPath(path1, _paint!);
     Path path2 = Path()
       ..moveTo(left, bottom - 10)
       ..lineTo(left, bottom)
       ..lineTo(left + 10, bottom);
-    canvas.drawPath(path2, _paint);
+    canvas.drawPath(path2, _paint!);
     Path path3 = Path()
       ..moveTo(right, bottom - 10)
       ..lineTo(right, bottom)
       ..lineTo(right - 10, bottom);
-    canvas.drawPath(path3, _paint);
+    canvas.drawPath(path3, _paint!);
     Path path4 = Path()
       ..moveTo(right, top + 10)
       ..lineTo(right, top)
       ..lineTo(right - 10, top);
-    canvas.drawPath(path4, _paint);
+    canvas.drawPath(path4, _paint!);
 
-    _paint.color = scanColor;
+    _paint!.color = scanColor;
 
-    final scanRect = Rect.fromLTWH(
-        left + 10, top + 10 + (value * (boxHeight - 20)), boxWidth - 20, 3);
+    final scanRect = Rect.fromLTWH(left + 10, top + 10 + (value * (boxHeight - 20)), boxWidth - 20, 3);
 
-    _paint.shader = LinearGradient(colors: <Color>[
+    _paint!.shader = LinearGradient(colors: <Color>[
       Colors.white54,
       Colors.white,
       Colors.white54,
@@ -214,7 +209,7 @@ class _ScanPainter extends CustomPainter {
       0.5,
       1,
     ]).createShader(scanRect);
-    canvas.drawRect(scanRect, _paint);
+    canvas.drawRect(scanRect, _paint!);
   }
 
   @override

+ 34 - 15
example/pubspec.lock

@@ -43,13 +43,6 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "1.15.0"
-  cupertino_icons:
-    dependency: "direct main"
-    description:
-      name: cupertino_icons
-      url: "https://pub.flutter-io.cn"
-    source: hosted
-    version: "0.1.3"
   fake_async:
     dependency: transitive
     description:
@@ -68,40 +61,59 @@ packages:
       name: flutter_plugin_android_lifecycle
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.0.11"
+    version: "2.0.1"
   flutter_test:
     dependency: "direct dev"
     description: flutter
     source: sdk
     version: "0.0.0"
+  flutter_web_plugins:
+    dependency: transitive
+    description: flutter
+    source: sdk
+    version: "0.0.0"
   http:
     dependency: transitive
     description:
       name: http
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.12.2"
+    version: "0.13.1"
   http_parser:
     dependency: transitive
     description:
       name: http_parser
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "3.1.4"
+    version: "4.0.0"
   image_picker:
     dependency: "direct main"
     description:
       name: image_picker
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.6.7+11"
+    version: "0.7.4"
+  image_picker_for_web:
+    dependency: transitive
+    description:
+      name: image_picker_for_web
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.0.0"
   image_picker_platform_interface:
     dependency: transitive
     description:
       name: image_picker_platform_interface
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.1.1"
+    version: "2.0.1"
+  js:
+    dependency: transitive
+    description:
+      name: js
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "0.6.3"
   matcher:
     dependency: transitive
     description:
@@ -129,21 +141,28 @@ packages:
       name: pedantic
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.9.2"
+    version: "1.11.0"
   permission_handler:
     dependency: "direct main"
     description:
       name: permission_handler
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "3.3.0"
+    version: "6.1.1"
+  permission_handler_platform_interface:
+    dependency: transitive
+    description:
+      name: permission_handler_platform_interface
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "3.1.1"
   plugin_platform_interface:
     dependency: transitive
     description:
       name: plugin_platform_interface
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.0.3"
+    version: "2.0.0"
   r_scan:
     dependency: "direct dev"
     description:

+ 23 - 23
example/test/widget_test.dart

@@ -1,27 +1,27 @@
-// This is a basic Flutter widget test.
-//
-// To perform an interaction with a widget in your test, use the WidgetTester
-// utility that Flutter provides. For example, you can send tap and scroll
-// gestures. You can also use WidgetTester to find child widgets in the widget
-// tree, read text, and verify that the values of widget properties are correct.
+// // This is a basic Flutter widget test.
+// //
+// // To perform an interaction with a widget in your test, use the WidgetTester
+// // utility that Flutter provides. For example, you can send tap and scroll
+// // gestures. You can also use WidgetTester to find child widgets in the widget
+// // tree, read text, and verify that the values of widget properties are correct.
 
-import 'package:flutter/material.dart';
-import 'package:flutter_test/flutter_test.dart';
+// import 'package:flutter/material.dart';
+// import 'package:flutter_test/flutter_test.dart';
 
-import 'package:r_scan_example/main.dart';
+// import 'package:r_scan_example/main.dart';
 
-void main() {
-  testWidgets('Verify Platform version', (WidgetTester tester) async {
-    // Build our app and trigger a frame.
-    await tester.pumpWidget(MyApp());
+// void main() {
+//   testWidgets('Verify Platform version', (WidgetTester tester) async {
+//     // Build our app and trigger a frame.
+//     await tester.pumpWidget(MyApp());
 
-    // Verify that platform version is retrieved.
-    expect(
-      find.byWidgetPredicate(
-        (Widget widget) =>
-            widget is Text && widget.data.startsWith('Running on:'),
-      ),
-      findsOneWidget,
-    );
-  });
-}
+//     // Verify that platform version is retrieved.
+//     expect(
+//       find.byWidgetPredicate(
+//         (Widget widget) =>
+//             widget is Text && widget.data.startsWith('Running on:'),
+//       ),
+//       findsOneWidget,
+//     );
+//   });
+// }

+ 138 - 138
lib/src/r_scan_view.dart

@@ -1,138 +1,138 @@
-// // Copyright 2019 The rhyme_lph Authors. All rights reserved.
-// // Use of this source code is governed by a BSD-style license that can be
-// // found in the LICENSE file.
-// import 'dart:async';
-// import 'dart:io';
-
-// import 'package:flutter/material.dart';
-// import 'package:flutter/services.dart';
-
-// import '../r_scan.dart';
-
-// const _scanType = 'com.rhyme_lph/r_scan_view';
-
-// typedef void ScanResultCallback(String result);
-
-// /// qr scan view , it need to  require camera permission.
-// @Deprecated("please use 'RScanCamera'")
-// class RScanView extends StatefulWidget {
-//   final RScanController controller;
-
-//   const RScanView({
-//     this.controller,
-//   }) : assert(controller != null);
-
-//   @override
-//   State<StatefulWidget> createState() => _RScanViewState();
-// }
-
-// class _RScanViewState extends State<RScanView> {
-//   RScanController _controller;
-
-//   void onPlatformViewCreated(int id) {
-//     _controller.attach(id);
-//   }
-
-//   @override
-//   void initState() {
-//     super.initState();
-//     _controller = widget.controller ?? RScanController();
-//     SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
-//   }
-
-//   @override
-//   void dispose() {
-//     super.dispose();
-//     _controller.detach();
-//   }
-
-//   @override
-//   Widget build(BuildContext context) {
-//     dynamic params = {
-//       "isPlay": _controller.isPlay,
-//     };
-//     Widget child;
-//     if (Platform.isAndroid) {
-//       child = AndroidView(
-//         viewType: _scanType,
-//         onPlatformViewCreated: onPlatformViewCreated,
-//         creationParams: params,
-//         creationParamsCodec: StandardMessageCodec(),
-//       );
-//     } else if (Platform.isIOS) {
-//       child = UiKitView(
-//         viewType: _scanType,
-//         onPlatformViewCreated: onPlatformViewCreated,
-//         creationParams: params,
-//         creationParamsCodec: StandardMessageCodec(),
-//       );
-//     } else {
-//       child = Container(
-//         child: Text('Not support ${Platform.operatingSystem} platform.'),
-//       );
-//     }
-
-//     return child;
-//   }
-// }
-
-// /// qr scan view controller .
-// /// can startScan or stopScan .
-// @Deprecated("please use 'RScanCameraController'")
-// class RScanController extends ChangeNotifier {
-//   Stream _stream;
-//   StreamSubscription _subscription;
-//   RScanResult result;
-//   EventChannel _channel;
-//   bool isPlay;
-//   MethodChannel _methodChannel;
-
-//   RScanController({this.isPlay: true})
-//       : assert(isPlay != null),
-//         super();
-
-//   void attach(int id) {
-//     _channel = EventChannel('${_scanType}_$id/event');
-//     _methodChannel = MethodChannel('${_scanType}_$id/method');
-//     _stream = _channel.receiveBroadcastStream(
-//       {
-//         "isPlay": isPlay,
-//       },
-//     );
-//     _subscription = _stream.listen((data) {
-//       this.result = RScanResult.formMap(data);
-//       notifyListeners();
-//     });
-//   }
-
-//   //开始扫描
-//   Future<void> startScan() async {
-//     await _methodChannel.invokeMethod('startScan');
-//   }
-
-//   //停止扫描
-//   Future<void> stopScan() async {
-//     await _methodChannel.invokeMethod('stopScan');
-//   }
-
-//   /// flash mode open or close.
-//   ///
-//   /// [isOpen] if false will close flash mode.
-//   ///
-//   /// It will return is success.
-//   Future<bool> setFlashMode(bool isOpen) async => await _methodChannel.invokeMethod('setFlashMode', {
-//         'isOpen': isOpen,
-//       });
-
-//   /// flash mode open or close.
-//   ///
-//   /// [isOpen] if false will close flash mode.
-//   ///
-//   /// It will return is success.
-//   Future<bool> getFlashMode() async => await _methodChannel.invokeMethod('getFlashMode');
-
-//   void detach() {
-//     _subscription?.cancel();
-//     notifyListeners();
-//   }
-// }
+// Copyright 2019 The rhyme_lph Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+import 'dart:async';
+import 'dart:io';
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+
+import '../r_scan.dart';
+
+const _scanType = 'com.rhyme_lph/r_scan_view';
+
+typedef void ScanResultCallback(String result);
+
+/// qr scan view , it need to  require camera permission.
+@Deprecated("please use 'RScanCamera'")
+class RScanView extends StatefulWidget {
+  final RScanController controller;
+
+  const RScanView({
+    required this.controller,
+  });
+
+  @override
+  State<StatefulWidget> createState() => _RScanViewState();
+}
+
+class _RScanViewState extends State<RScanView> {
+  late RScanController _controller;
+
+  void onPlatformViewCreated(int id) {
+    _controller.attach(id);
+  }
+
+  @override
+  void initState() {
+    super.initState();
+    _controller = widget.controller ?? RScanController();
+    SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
+  }
+
+  @override
+  void dispose() {
+    super.dispose();
+    _controller.detach();
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    dynamic params = {
+      "isPlay": _controller.isPlay,
+    };
+    Widget child;
+    if (Platform.isAndroid) {
+      child = AndroidView(
+        viewType: _scanType,
+        onPlatformViewCreated: onPlatformViewCreated,
+        creationParams: params,
+        creationParamsCodec: StandardMessageCodec(),
+      );
+    } else if (Platform.isIOS) {
+      child = UiKitView(
+        viewType: _scanType,
+        onPlatformViewCreated: onPlatformViewCreated,
+        creationParams: params,
+        creationParamsCodec: StandardMessageCodec(),
+      );
+    } else {
+      child = Container(
+        child: Text('Not support ${Platform.operatingSystem} platform.'),
+      );
+    }
+
+    return child;
+  }
+}
+
+/// qr scan view controller .
+/// can startScan or stopScan .
+@Deprecated("please use 'RScanCameraController'")
+class RScanController extends ChangeNotifier {
+  late Stream _stream;
+  late StreamSubscription _subscription;
+  RScanResult? result;
+  late EventChannel _channel;
+  bool isPlay;
+  late MethodChannel _methodChannel;
+
+  RScanController({
+    this.isPlay: true,
+  }) : super();
+
+  void attach(int id) {
+    _channel = EventChannel('${_scanType}_$id/event');
+    _methodChannel = MethodChannel('${_scanType}_$id/method');
+    _stream = _channel.receiveBroadcastStream(
+      {
+        "isPlay": isPlay,
+      },
+    );
+    _subscription = _stream.listen((data) {
+      this.result = RScanResult.formMap(data);
+      notifyListeners();
+    });
+  }
+
+  //开始扫描
+  Future<void> startScan() async {
+    await _methodChannel.invokeMethod('startScan');
+  }
+
+  //停止扫描
+  Future<void> stopScan() async {
+    await _methodChannel.invokeMethod('stopScan');
+  }
+
+  /// flash mode open or close.
+  ///
+  /// [isOpen] if false will close flash mode.
+  ///
+  /// It will return is success.
+  Future<bool> setFlashMode(bool isOpen) async => await _methodChannel.invokeMethod('setFlashMode', {
+        'isOpen': isOpen,
+      });
+
+  /// flash mode open or close.
+  ///
+  /// [isOpen] if false will close flash mode.
+  ///
+  /// It will return is success.
+  Future<bool> getFlashMode() async => await _methodChannel.invokeMethod('getFlashMode');
+
+  void detach() {
+    _subscription?.cancel();
+    notifyListeners();
+  }
+}