Flutter高仿微信系列共59篇,从Flutter客户端、Kotlin客户端、Web服务器、数据库表结构、Xmpp即时通讯服务器、视频通话服务器、腾讯云服务器全面讲解。
详情请查看
效果图:
实现代码:
//二维码扫一扫 Future _scanQR() async { try { final result = await BarcodeScanner.scan( options: ScanOptions( strings: { 'cancel': _cancelController.text, 'flash_on': _flashOnController.text, 'flash_off': _flashOffController.text, }, restrictFormat: selectedFormats, useCamera: _selectedCamera, autoEnableFlash: _autoEnableFlash, android: AndroidOptions( aspectTolerance: _aspectTolerance, useAutoFocus: _useAutoFocus, ), ), ); _processQRResult(result); } on PlatformException catch (e) { String errorResult = e.code == BarcodeScanner.cameraAccessDenied ? '没有拍照权限!': 'Unknown error: $e'; LogUtils.d("扫一扫返回异常:${errorResult}"); } }
//处理扫描结果 void _processQRResult(ScanResult result){ if(result == null){ return; } if (result.rawContent.startsWith(CommonUtils.QR_PAYMENT_CODE)){ //向商家付款 String toUser = result.rawContent.substring(CommonUtils.QR_PAYMENT_CODE.length, result.rawContent.length); Navigator.push(context, MaterialPageRoute(builder: (context) => MerchantPayment(toUser: toUser))); } else if(result.rawContent.startsWith(CommonUtils.QR_RECEIVE_CODE)){ //二维码收款 String receiveResult = result.rawContent.substring(CommonUtils.QR_PAYMENT_CODE.length, result.rawContent.length); String balance = receiveResult.split(":")[0]; String toUser = receiveResult.split(":")[1]; LogUtils.d("扫一扫返回结果 ${receiveResult} , ${balance} , ${toUser}"); Navigator.push(context, MaterialPageRoute(builder: (context) => PersonalPayment(toUser: toUser, balance: double.parse(balance),))); } else if(result != null){ //添加好友 String content = result.rawContent; List<String> contentList = content.split(CommonUtils.CHAT_MESSAGE_SPILE); String accountStr = contentList[0]; String nickName = contentList[1]; String avatar = contentList[2]; String accountResult = accountStr.substring(CommonUtils.QR_ADD_FRIEND.length, accountStr.length); UserBean userBean = UserBean(account: accountResult, avatar: avatar, nickName: nickName); LogUtils.d("扫一扫返回结果:${accountStr} , ${nickName} , ${avatar}, ${accountResult}"); _goSearchFriends(accountResult, userBean); } }