Skip to content

Commit

Permalink
#70 QR 암호화, 카메라 자동으로 켜지도록 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
opjoobe committed Aug 3, 2022
1 parent 594663f commit dc11ccc
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions lib/screens/sharing/sharing_qr_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:qr_flutter/qr_flutter.dart';
import 'package:barcode_scan2/barcode_scan2.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:socket_io_client/socket_io_client.dart';
import 'dart:convert';

import '../mypage/profile_page.dart';

Expand Down Expand Up @@ -46,6 +47,8 @@ class _QRforTOOKState extends State<QRforTOOK> {
Barcode? result;
QRViewController? controller;
dynamic socket;
Codec<String, String> stringToBase64 = utf8.fuse(base64);

void setStateIfMounted(f) {
if (mounted) setState(f);
}
Expand All @@ -61,7 +64,7 @@ class _QRforTOOKState extends State<QRforTOOK> {
socket.on('connect', (data) {
debugPrint('socket connected');
if (widget.isSender) {
socket.emit('join', 'QR${widget.myId}');
socket.emit('join', 'QRTOOKExchange${widget.myId.toString()}');
}
debugPrint('연결완료');
});
Expand Down Expand Up @@ -99,19 +102,27 @@ class _QRforTOOKState extends State<QRforTOOK> {
void initState() {
// TODO: implement initState
initializeSocket();
Future.delayed(Duration(milliseconds: 600), () async {
await controller?.resumeCamera();
});
super.initState();
var encodeId =
stringToBase64.encode('QRTOOKExchange${widget.myId.toString()}');
var decodeId = stringToBase64.decode(encodeId);
print('encodeId: $encodeId');
print('decodeId: $decodeId');
}

// In order to get hot reload to work we need to pause the camera if the platform
// is android, or resume the camera if the platform is iOS.
@override
void reassemble() {
super.reassemble();
if (Platform.isAndroid) {
controller!.pauseCamera();
} else if (Platform.isIOS) {
controller!.resumeCamera();
}
// if (Platform.isAndroid) {
// controller!.pauseCamera();
// } else if (Platform.isIOS) {
// controller!.resumeCamera();
// }
}

@override
Expand All @@ -121,7 +132,8 @@ class _QRforTOOKState extends State<QRforTOOK> {
body: widget.isSender
? Center(
child: QrImage(
data: widget.myId.toString(),
data: stringToBase64
.encode('QRTOOKExchange${widget.myId.toString()}'),
backgroundColor: Colors.white,
size: 200,
))
Expand Down Expand Up @@ -154,14 +166,16 @@ class _QRforTOOKState extends State<QRforTOOK> {
this.controller = controller;
controller.scannedDataStream.listen((scanData) {
int senderId;
String? senderIdinStr = scanData.code;
senderId = int.parse(senderIdinStr!);
String? chatRoomId = stringToBase64
.decode(scanData.code!); // 'QRTOOKExchange${widget.myId.toString()}'
String? senderIdinStr = chatRoomId.substring(14);
senderId = int.parse(senderIdinStr);

setState(() {
result = scanData;
socket.emit('join', 'QR$senderId');
socket.emit('join', chatRoomId);
socket.emit('took', {
'chatroomID': 'QR$senderId',
'chatroomID': 'QR${senderId.toString()}',
'senderID': senderId,
'receiverID': widget.myId
}); // 칭구
Expand Down

0 comments on commit dc11ccc

Please sign in to comment.