From 714a0b1c11b3145f052414adcc1eb39338522de8 Mon Sep 17 00:00:00 2001 From: opjoobe Date: Wed, 3 Aug 2022 17:01:08 +0900 Subject: [PATCH] #70 qr bug fix, punch bug fix --- lib/screens/sharing/punch.dart | 36 ++++++++++++++---------- lib/screens/sharing/sharing_qr_page.dart | 28 ++++++++++-------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/lib/screens/sharing/punch.dart b/lib/screens/sharing/punch.dart index 8689439..ee303c9 100644 --- a/lib/screens/sharing/punch.dart +++ b/lib/screens/sharing/punch.dart @@ -19,16 +19,17 @@ class PunchPage extends StatefulWidget { class _PunchPageState extends State { final Color _backgroundColor = Color.fromARGB(255, 255, 255, 255); List? _userAccelerometerValues; - var cnt = 0; + bool isTooked = false; @override void initState() { // super.initState(); - userAccelerometerEvents.listen((UserAccelerometerEvent event) { - setState(() { - // Manipulate the UI here, something like: - if ((event.y > 5 || event.y < -5) && cnt == 0) { - cnt++; + if (!isTooked) { + userAccelerometerEvents.listen((UserAccelerometerEvent event) { + if ((event.y > 5 || event.y < -5) && !isTooked) { + setState(() { + isTooked = true; + }); Navigator.push( context, MaterialPageRoute( @@ -37,8 +38,10 @@ class _PunchPageState extends State { friendId: widget.friendId, latlng: widget.latlng, ))); - } else if ((event.x < -4 || event.x > 4) && cnt == 0) { - cnt++; + } else if ((event.x < -4 || event.x > 4) && !isTooked) { + setState(() { + isTooked = true; + }); Navigator.push( context, @@ -48,8 +51,10 @@ class _PunchPageState extends State { friendId: widget.friendId, latlng: widget.latlng, ))); - } else if ((event.z < -4 || event.z > 4) && cnt == 0) { - cnt++; + } else if ((event.z < -4 || event.z > 4) && !isTooked) { + setState(() { + isTooked = true; + }); Navigator.push( context, MaterialPageRoute( @@ -59,12 +64,13 @@ class _PunchPageState extends State { latlng: widget.latlng, ))); } else {} - super.dispose(); - for (final subscription in _streamSubscriptions) { - subscription.cancel(); - } }); - }); + } else { + super.dispose(); + for (final subscription in _streamSubscriptions) { + subscription.cancel(); + } + } } final _streamSubscriptions = >[]; diff --git a/lib/screens/sharing/sharing_qr_page.dart b/lib/screens/sharing/sharing_qr_page.dart index 32be417..1b4bdab 100644 --- a/lib/screens/sharing/sharing_qr_page.dart +++ b/lib/screens/sharing/sharing_qr_page.dart @@ -78,8 +78,10 @@ class _QRforTOOKState extends State { }); socket.on('took', (data) { - int friendId = widget.isSender ? data.receiverID : data.senderID; - socket.emit('leave', data.chatroomID); // receiver, sender 공통 + var tookData = Map.from(data); + int friendId = + widget.isSender ? tookData['receiverID'] : tookData['senderID']; + socket.emit('leave', tookData['chatroomID']); // receiver, sender 공통 socket.emit('disconnect'); Navigator.push( context, @@ -166,19 +168,21 @@ class _QRforTOOKState extends State { this.controller = controller; controller.scannedDataStream.listen((scanData) { int senderId; - 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', chatRoomId); - socket.emit('took', { - 'chatroomID': chatRoomId, - 'senderID': senderId, - 'receiverID': widget.myId - }); // 칭구 + if (result != null) { + String? chatRoomId = stringToBase64.decode( + result!.code!); // 'QRTOOKExchange${widget.myId.toString()}' + String? senderIdinStr = chatRoomId.substring(14); + senderId = int.parse(senderIdinStr); + socket.emit('join', chatRoomId); + socket.emit('took', { + 'chatroomID': chatRoomId, + 'senderID': senderId, + 'receiverID': widget.myId + }); + } // 칭구 }); }); }