Skip to content

Commit d52f66f

Browse files
committed
[receieve] サーバーへの接続のタイムアウトを設定
1 parent b06e86d commit d52f66f

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

lib/receieve.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ class ReceiveFile {
2525
return WillPopScope(
2626
// 戻る無効化
2727
onWillPop: () => Future.value(false),
28-
child: AlertDialog(
29-
title: const Text("接続しています..."),
30-
actions: <Widget>[
31-
TextButton(
32-
onPressed: () => connectionTask.cancel(),
33-
child: const Text("キャンセル")),
34-
],
28+
child: const AlertDialog(
29+
title: Text(
30+
"接続しています...",
31+
textAlign: TextAlign.center,
32+
),
3533
),
3634
);
3735
});
@@ -41,8 +39,8 @@ class ReceiveFile {
4139

4240
// 最初の接続を開始
4341
try {
44-
connectionTask = await Socket.startConnect(ip, 4782);
45-
socket = await connectionTask.socket;
42+
socket =
43+
await Socket.connect(ip, 4782, timeout: const Duration(seconds: 10));
4644
socket.add(utf8.encode("first"));
4745
} on SocketException catch (e) {
4846
Wakelock.disable();

0 commit comments

Comments
 (0)