티스토리 뷰
반응형
import 'dart:async';
import 'dart:convert';
import 'dart:io';
final garageExternalIP = '192.168.86.40';
const garagePort = 1416;
const garageEventType = 'event_type';
const garageResponse = 'response';
const garageEventDelay = 'delay';
const garageOpenEvent = 1;
const garageCloseEvent = 2;
const garageTriggerEvent = 3;
const garageIsOpenEvent = 4;
const garageCloseInEvent = 5;
const garageOpenForEvent = 6;
bool _onBadCertificate(X509Certificate cert) => true;
static Future<bool> _sendRequest(int type,
{int delay, bool returnResponse = false}) async {
try {
final connection = await SecureSocket.connect(
garageExternalIP, garagePort,
context: _context, onBadCertificate: _onBadCertificate);
final request = {
garageEventType: type,
};
if (delay != null) {
request[garageEventDelay] = delay;
}
connection.write(json.encode(request));
if (returnResponse) {
final completer = Completer<bool>();
connection.listen((r) {
final Map response = json.decode(utf8.decode(r));
completer.complete(response[garageResponse]);
});
connection.close();
return completer.future;
}
connection.close();
return true;
} catch (e) {
print('Client Error: $e');
return false;
}
}
}
반응형
'Flutter' 카테고리의 다른 글
flutter combobox 어렵네... (0) | 2022.08.26 |
---|---|
flutter i폰 앱 디버깅 - Could not build the precompiled application for the device. (0) | 2022.06.27 |
flutter err (0) | 2022.06.24 |
맥북에서 Flutter 설치하기 (0) | 2022.06.17 |
flutter에서 StatelessWidget 화면 갱신 (0) | 2022.05.31 |