我有一个内部函数,但是当我离开这个页面时,这个内部函数是否拥有对外部类的引用?
拿着它怎么办?
如何编写代码?
谢谢
有这样的回调,
FlutterDownloader.registerCallback();
在下载文件的过程中,我将离开页面。这个函数是否拥有对外部类的引用?握住该怎么办?
谢谢
class _DictOfflineDownloadPageState extends BasePageState<DictOfflineDownloadPage> {
OfflineDictsHandle _offlineDictsHandle;
StreamSubscription _subscription;
List<DownLoadItem> _downLoads = <DownLoadItem>[];
bool _isLoading = true;
MyLocalizations _localizations;
@override
String pageTag() => _tag;
@override
void initState() {
super.initState();
_localizations = widget._localizations;
OfflineDictsHandle.create().then((_h) {
_offlineDictsHandle = _h;
_subscription = _offlineDictsHandle.onDictsUpdate.listen(_init);
_offlineDictsHandle.start();
});
FlutterDownloader.registerCallback((String id, DownloadTaskStatus status, int progress) {
DownLoadItem dItem = _downLoads.firstWhere((item) => item.taskId == id);
if (dItem != null) {
if (progress < 0) {
progress = 0;
status = DownloadTaskStatus.undefined;
}
dItem.progress = progress;
dItem.status = status;
if (status == DownloadTaskStatus.complete) {
dItem.initDescription();
FlutterDownloader.loadTasksWithRawQuery(
query: "SELECT * FROM task WHERE task_id = '${dItem.taskId}'")
.then((tasks) {
if (tasks.length > 0) {
OfflineDictsHandle.SetDownloaded(
dItem.meta.id, '${dItem.localPath}/${tasks[0].filename}', dItem.meta.version);
dItem.delete();
}
});
_removeDownloadCallback();
}
if (mounted) {
setState(() {});
}
}
});
}
}