From 8d35f63fa46cbb13f3d99ec7b6f675603e8c770c Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Sat, 5 Jul 2025 15:56:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=9A=E8=AE=AE=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=E8=87=AA=E5=8A=A8=E8=BF=9E=E6=8E=A5Wi-Fi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meeting_connect_controller.dart | 32 +++++++++---------- pubspec.yaml | 1 + 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/modules/meeting/controllers/meeting_connect_controller.dart b/lib/modules/meeting/controllers/meeting_connect_controller.dart index cceb82ddf..af101e1cb 100644 --- a/lib/modules/meeting/controllers/meeting_connect_controller.dart +++ b/lib/modules/meeting/controllers/meeting_connect_controller.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:get/get.dart'; +import 'package:wifi_iot/wifi_iot.dart'; class MeetingConnectController extends GetxController { RxString stateStr = '搜索中...'.obs; @@ -25,8 +26,6 @@ class MeetingConnectController extends GetxController { String _ftpAccount = ''; String _ftpPassword = ''; - bool _isConnectWifi = false; - @override void onInit() { super.onInit(); @@ -87,6 +86,7 @@ class MeetingConnectController extends GetxController { } Future _disconnect() async { + await WiFiForIoTPlugin.disconnect(); await _device?.disconnect(); } @@ -158,15 +158,15 @@ class MeetingConnectController extends GetxController { break; case 0x03: // FTP 地址 _ftpAddress = String.fromCharCodes(value.sublist(3, value.length - 2)); - _connectFtp(); + sendData([0x5a, 0x01, 0x04]); break; case 0x04: // FTP 端口 _ftpPort = String.fromCharCodes(value.sublist(3, value.length - 2)); - _connectFtp(); + sendData([0x5a, 0x01, 0x05]); break; case 0x05: // FTP 账号 _ftpAccount = String.fromCharCodes(value.sublist(3, value.length - 2)); - _connectFtp(); + sendData([0x5a, 0x01, 0x06]); break; case 0x06: // FTP 密码 _ftpPassword = _decodePassword(value); @@ -181,23 +181,21 @@ class MeetingConnectController extends GetxController { await sendData([0x5a, 0x01, 0x0c]); } - void _getFtp() async { - await sendData([0x5a, 0x01, 0x03]); - await sendData([0x5a, 0x01, 0x04]); - await sendData([0x5a, 0x01, 0x05]); - await sendData([0x5a, 0x01, 0x06]); - } - - void _connectWifi() { + void _connectWifi() async { if (_wifiSSID.isNotEmpty && _wifiPassword.isNotEmpty) { - _getFtp(); + stateStr.value = '正在连接 Wi-Fi...'; + await WiFiForIoTPlugin.connect( + _wifiSSID, + password: _wifiPassword, + security: NetworkSecurity.WPA, + ); + stateStr.value = 'Wi-Fi 连接成功'; + sendData([0x5a, 0x01, 0x03]); } - _connectFtp(); } void _connectFtp() { - if (_isConnectWifi && - _ftpAddress.isNotEmpty && + if (_ftpAddress.isNotEmpty && _ftpPort.isNotEmpty && _ftpAccount.isNotEmpty && _ftpPassword.isNotEmpty) {} diff --git a/pubspec.yaml b/pubspec.yaml index e01fc5fb8..32cdf99ff 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: git: url: https://github.com/AppFlowy-IO/appflowy-editor.git ref: main + wifi_iot: ^0.3.19+2 permission_handler: ^10.4.5 web_socket_channel: ^2.4.0 flutter_dotenv: ^5.1.0