fix jobTable state can't update

This commit is contained in:
csf 2023-03-09 11:40:06 +09:00
parent a2f82b6ea6
commit 970dfa3c88
2 changed files with 14 additions and 5 deletions

View File

@ -157,10 +157,10 @@ class _FileManagerPageState extends State<FileManagerPage>
/// transfer status list /// transfer status list
/// watch transfer status /// watch transfer status
Widget statusList() { Widget statusList() {
statusListView() => Obx(() => ListView.builder( statusListView(List<JobProgress> jobs) => ListView.builder(
controller: ScrollController(), controller: ScrollController(),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
final item = jobController.jobTable[index]; final item = jobs[index];
return Padding( return Padding(
padding: const EdgeInsets.only(bottom: 5), padding: const EdgeInsets.only(bottom: 5),
child: generateCard( child: generateCard(
@ -281,7 +281,7 @@ class _FileManagerPageState extends State<FileManagerPage>
); );
}, },
itemCount: jobController.jobTable.length, itemCount: jobController.jobTable.length,
)); );
return PreferredSize( return PreferredSize(
preferredSize: const Size(200, double.infinity), preferredSize: const Size(200, double.infinity),
@ -312,7 +312,7 @@ class _FileManagerPageState extends State<FileManagerPage>
), ),
), ),
) )
: statusListView(), : statusListView(jobController.jobTable),
)), )),
); );
} }

View File

@ -100,6 +100,7 @@ class FileModel {
jobController.cancelJob(id); jobController.cancelJob(id);
final job = jobController.jobTable[jobIndex]; final job = jobController.jobTable[jobIndex];
job.state = JobState.done; job.state = JobState.done;
jobController.jobTable.refresh();
} }
} else { } else {
var need_override = false; var need_override = false;
@ -286,7 +287,9 @@ class FileController {
void changeSortStyle(SortBy sort, {bool? isLocal, bool ascending = true}) { void changeSortStyle(SortBy sort, {bool? isLocal, bool ascending = true}) {
sortBy.value = sort; sortBy.value = sort;
sortAscending = ascending; sortAscending = ascending;
directory.value.changeSortStyle(sort, ascending: ascending); directory.update((dir) {
dir?.changeSortStyle(sort, ascending: ascending);
});
} }
Future<void> refresh() async { Future<void> refresh() async {
@ -374,6 +377,7 @@ class FileController {
job.totalSize = totalSize; job.totalSize = totalSize;
job.fileCount = fileCount; job.fileCount = fileCount;
debugPrint("update receive details:${fd.path}"); debugPrint("update receive details:${fd.path}");
jobController.jobTable.refresh();
} }
} else if (options.value.home.isEmpty) { } else if (options.value.home.isEmpty) {
options.value.home = fd.path; options.value.home = fd.path;
@ -631,6 +635,7 @@ class JobController {
job.speed = double.parse(evt['speed']); job.speed = double.parse(evt['speed']);
job.finishedSize = int.parse(evt['finished_size']); job.finishedSize = int.parse(evt['finished_size']);
debugPrint("update job $id with $evt"); debugPrint("update job $id with $evt");
jobTable.refresh();
} }
} catch (e) { } catch (e) {
debugPrint("Failed to tryUpdateJobProgress,evt:${evt.toString()}"); debugPrint("Failed to tryUpdateJobProgress,evt:${evt.toString()}");
@ -650,6 +655,7 @@ class JobController {
job.finishedSize = job.totalSize; job.finishedSize = job.totalSize;
job.state = JobState.done; job.state = JobState.done;
job.fileNum = int.parse(evt['file_num']); job.fileNum = int.parse(evt['file_num']);
jobTable.refresh();
} }
} }
@ -665,6 +671,7 @@ class JobController {
job.state = JobState.done; job.state = JobState.done;
job.finishedSize = job.totalSize; job.finishedSize = job.totalSize;
} }
jobTable.refresh();
} }
debugPrint("jobError $evt"); debugPrint("jobError $evt");
} }
@ -713,6 +720,7 @@ class JobController {
bind.sessionResumeJob( bind.sessionResumeJob(
id: sessionID, actId: job.id, isRemote: job.isRemoteToLocal); id: sessionID, actId: job.id, isRemote: job.isRemoteToLocal);
job.state = JobState.inProgress; job.state = JobState.inProgress;
jobTable.refresh();
} else { } else {
debugPrint("jobId $jobId is not exists"); debugPrint("jobId $jobId is not exists");
} }
@ -729,6 +737,7 @@ class JobController {
final job = jobTable[jobIndex]; final job = jobTable[jobIndex];
job.fileCount = num_entries; job.fileCount = num_entries;
job.totalSize = total_size.toInt(); job.totalSize = total_size.toInt();
jobTable.refresh();
} }
debugPrint("update folder files: $info"); debugPrint("update folder files: $info");
} }