jyj 4 年之前
父节点
当前提交
051574ed1e
共有 3 个文件被更改,包括 74 次插入40 次删除
  1. 57 24
      lib/internal/wode/page/wode_page.dart
  2. 13 13
      lib/utils/utils.dart
  3. 4 3
      pubspec.yaml

+ 57 - 24
lib/internal/wode/page/wode_page.dart

@@ -21,7 +21,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:image_picker/image_picker.dart';
 import 'package:liftmanager/utils/toast.dart';
 import 'package:liftmanager/utils/utils.dart';
-import 'package:barcode_scan/barcode_scan.dart';
+// import 'package:barcode_scan/barcode_scan.dart';
+import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
 import 'package:flutter/services.dart';
 import 'package:flustars/flustars.dart' as FlutterStars;
 import 'package:liftmanager/utils/fast_notification.dart';
@@ -86,17 +87,55 @@ class WodePageState extends State<WodePage> with AutomaticKeepAliveClientMixin {
     );
   }
 
-  Future scan() async {
+  // Future scan() async {
+  //   try {
+  //     // 此处为扫码结果,barcode为二维码的内容
+  //     String barcode = await BarcodeScanner.scan();
+  //     print(barcode);
+  //     // http://lift.whlhcx.com/h5/index.html?page=/wode/vip&id=1288674418578472962
+  //     // return;
+  //     // print('扫码结果: ' + jsonDecode(barcode)["url"]);
+  //     Uri u = Uri.parse(barcode);
+  //     String id = u.queryParameters['id'];
+  //     print('扫码结果: ' + id);
+  //     // print('扫码结果: ' + jsonDecode(barcode)["userId"].toString());
+
+  //     NewApiService().getUserRebates(id,
+  //         onSuccess: (res) {
+  //           toastsF(context,"你已成功接受${res!=null?res.toString():''}的邀请,立即成为会员!",timeInSecForIos:3);
+  //           // toasts("您已成为${res!=null?res.toString():''}的下级用户");
+  //       NavigatorUtils.push(context, "${WodeRouter.vip}?id=");
+  //     }, onError: (code, msg) {
+  //       toasts(msg);
+  //     });
+  //   } on PlatformException catch (e) {
+  //     if (e.code == BarcodeScanner.CameraAccessDenied) {
+  //       // 未授予APP相机权限
+  //       print('未授予APP相机权限');
+  //     } else {
+  //       // 扫码错误
+  //       print('扫码错误: $e');
+  //     }
+  //   } on FormatException {
+  //     // 进入扫码页面后未扫码就返回
+  //     print('进入扫码页面后未扫码就返回');
+  //   } catch (e) {
+  //     // 扫码错误
+  //     print('扫码错误: $e');
+  //   }
+  // }
+
+  Future<void> scan() async {
+    String barcodeScanRes;
+    // Platform messages may fail, so we use a try/catch PlatformException.
     try {
-      // 此处为扫码结果,barcode为二维码的内容
-      String barcode = await BarcodeScanner.scan();
-      print(barcode);
-      // return;
-      // print('扫码结果: ' + jsonDecode(barcode)["url"]);
-      Uri u = Uri.parse(barcode);
+      barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
+          "#ff6666", "取消", true, ScanMode.BARCODE);
+      print(123456);
+      print(barcodeScanRes);
+      Uri u = Uri.parse(barcodeScanRes);
       String id = u.queryParameters['id'];
-      print('扫码结果: ' + id);
-      // print('扫码结果: ' + jsonDecode(barcode)["userId"].toString());
+      print("123456--" + id);
 
       NewApiService().getUserRebates(id,
           onSuccess: (res) {
@@ -106,21 +145,15 @@ class WodePageState extends State<WodePage> with AutomaticKeepAliveClientMixin {
       }, onError: (code, msg) {
         toasts(msg);
       });
-    } on PlatformException catch (e) {
-      if (e.code == BarcodeScanner.CameraAccessDenied) {
-        // 未授予APP相机权限
-        print('未授予APP相机权限');
-      } else {
-        // 扫码错误
-        print('扫码错误: $e');
-      }
-    } on FormatException {
-      // 进入扫码页面后未扫码就返回
-      print('进入扫码页面后未扫码就返回');
-    } catch (e) {
-      // 扫码错误
-      print('扫码错误: $e');
+    } on PlatformException {
+      barcodeScanRes = 'Failed to get platform version.';
     }
+
+    // If the widget was removed from the tree while the asynchronous platform
+    // message was in flight, we want to discard the reply rather than calling
+    // setState to update our non-existent appearance.
+    if (!mounted) return;
+
   }
 
   Future getCoupon() async {

+ 13 - 13
lib/utils/utils.dart

@@ -1,6 +1,6 @@
 import 'dart:convert';
 
-import 'package:barcode_scan/barcode_scan.dart';
+// import 'package:barcode_scan/barcode_scan.dart';
 import 'package:crypto/crypto.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
@@ -92,18 +92,18 @@ class Utils {
   }
 
   /// 调起二维码扫描页
-  static Future<String> scan(context) async {
-    try {
-      return await BarcodeScanner.scan();
-    } catch (e) {
-      if (e is PlatformException) {
-        if (e.code == BarcodeScanner.CameraAccessDenied) {
-          toasts("没有相机权限!");
-        }
-      }
-    }
-    return null;
-  }
+  // static Future<String> scan(context) async {
+  //   try {
+  //     return await BarcodeScanner.scan();
+  //   } catch (e) {
+  //     if (e is PlatformException) {
+  //       if (e.code == BarcodeScanner.CameraAccessDenied) {
+  //         toasts("没有相机权限!");
+  //       }
+  //     }
+  //   }
+  //   return null;
+  // }
 
   static KeyboardActionsConfig getKeyboardActionsConfig(
       BuildContext context, List<FocusNode> list) {

+ 4 - 3
pubspec.yaml

@@ -64,9 +64,10 @@ dependencies:
   # 启动URL的插件
   url_launcher: ^5.4.2
   # 扫码
-  barcode_scan:
-    git:
-      url: https://github.com/simplezhli/flutter_barcode_reader.git
+  flutter_barcode_scanner: ^1.0.1
+  # barcode_scan:
+  #   git:
+  #     url: https://github.com/simplezhli/flutter_barcode_reader.git
   # 图片选择插件
   image_picker: 0.6.2+1
   # 网络状态