Browse Source

优化会议助手下载文件

weicu
tanlongsheng 1 year ago
parent
commit
40addfe0d4
  1. 18
      lib/modules/meeting/controllers/meeting_connect_controller.dart
  2. 15
      lib/modules/meeting/views/meeting_connect_view.dart
  3. 3
      lib/modules/meeting/views/meeting_view.dart

18
lib/modules/meeting/controllers/meeting_connect_controller.dart

@ -14,7 +14,6 @@ class MeetingConnectController extends GetxController {
RxString stateStr = '搜索中...'.obs;
RxBool isRescan = false.obs;
RxBool isImportedFiles = false.obs;
RxString importedFilesStr = ''.obs;
late StreamSubscription<List<ScanResult>> _scanResultsSubscription;
@ -151,10 +150,10 @@ class MeetingConnectController extends GetxController {
switch (command) {
case 0x0d: // 是否有导入文件
if (value[3] == 0x01) {
isImportedFiles.value = true;
importedFilesStr.value = '检查到有新文件,是否导入';
stateStr.value = '正在开启Wi-Fi...';
importedFilesStr.value = '检查到有新文件,正在准备导入';
sendData([0x5a, 0x02, 0x87, 0x01]);
} else {
isImportedFiles.value = false;
importedFilesStr.value = '没有新文件需要导入';
}
break;
@ -220,19 +219,25 @@ class MeetingConnectController extends GetxController {
_ftpConnect?.listCommand = ListCommand.LIST;
List<FTPEntry>? listDirectory = await _ftpConnect?.listDirectoryContent();
if (listDirectory != null && listDirectory.isNotEmpty) {
stateStr.value = '正在下载文件...';
isDownload.value = true;
int totalSize = listDirectory.fold(
0,
(sum, entry) => sum + (entry.size ?? 0),
);
for (var i = 0; i < listDirectory.length; i++) {
stateStr.value = '共${listDirectory.length}个文件,正在下载第${i + 1}个文件...';
importedFilesStr.value =
'共${listDirectory.length}个文件,正在下载第${i + 1}个文件';
int previousSize = i > 0 ? listDirectory[i - 1].size ?? 0 : 0;
FTPEntry element = listDirectory[i];
await _downloadFile(totalSize, previousSize, element);
}
stateStr.value = '下载完成,共${listDirectory.length}个文件';
stateStr.value = '下载完成';
importedFilesStr.value = '下载完成,共${listDirectory.length}个文件,2秒后自动返回';
_disconnect();
Future.delayed(const Duration(seconds: 2), () {
Get.back();
});
}
}
}
@ -249,6 +254,7 @@ class MeetingConnectController extends GetxController {
await _ftpConnect?.downloadFileWithRetry(
entry.name,
localFile,
pRetryCount: 3,
onProgress: (double progress, int received, int size) {
downloadProgress.value = (previousSize + received) / totalSize;
totalReceived.value = received;

15
lib/modules/meeting/views/meeting_connect_view.dart

@ -76,26 +76,13 @@ class MeetingConnectView extends GetView<MeetingConnectController> {
),
),
),
Obx(
() => controller.isImportedFiles.value
? Padding(
padding: EdgeInsets.symmetric(vertical: 10.w),
child: _button('导入文件', Icons.file_download, onTap: () {
controller.stateStr.value = '正在开启Wi-Fi...';
controller.importedFilesStr.value = '';
controller.isImportedFiles.value = false;
controller.sendData([0x5a, 0x02, 0x87, 0x01]);
}),
)
: const SizedBox(),
),
Obx(() => controller.isDownload.value
? Column(
children: [
Container(
width: 300.w,
height: 3.w,
margin: EdgeInsets.only(bottom: 10.w),
margin: EdgeInsets.symmetric(vertical: 10.w),
child: LinearProgressIndicator(
value: controller.downloadProgress.value,
valueColor:

3
lib/modules/meeting/views/meeting_view.dart

@ -423,6 +423,7 @@ class MeetingView extends GetView<MeetingController> {
PreferredSizeWidget _buildAppBar(BuildContext context, bool isDarkMode) {
return AppBar(
backgroundColor: isDarkMode ? Colors.black : Colors.white,
surfaceTintColor: Colors.transparent,
elevation: 0.5,
leading: IconButton(
icon: Icon(
@ -459,7 +460,7 @@ class MeetingView extends GetView<MeetingController> {
() => ListView.builder(
controller: controller.listController,
itemCount: controller.dataList.length,
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 5.w),
padding: EdgeInsets.fromLTRB(12.w, 5.w, 12.w, 90.w),
itemBuilder: (BuildContext context, int index) {
MeetingModel data = MeetingModel.fromJson(controller.dataList[index]);
return _item(context, isDarkMode, data);

Loading…
Cancel
Save