alibaba / alibaba/flutter_boost
同一个container接连打开两个返回结果的原生页面,第二次打开的页面接收不到结果
- Dominant language
- Dart
- Stars
- 7.2k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
场景:
假设有一个flutter页面A,两个原生页面B和C。
A页面打开B页面,在B页面返回的结果中继续打开C页面。
BoostNavigator.instance.push(
‘B',
withContainer: true,
arguments: {},
opaque: true,
).then((dynamic result) {
// 能正常返回
flutterLog("flutterboost.resultHandler: result.B: $result");
// 返回结果中打开C页面
BoostNavigator.instance.push(
‘C',
withContainer: true,
arguments: {},
opaque: true,
).then((dynamic result) {
// 一打开C页面,该回调立马执行,返回null。
flutterLog("flutterboost.resultHandler: result.C: $result");
});
});
经过源码定位,发现是下面代码导致:
void onContainerShow(CommonParams params) {
final container = _findContainerByUniqueId(params.uniqueId)!;
BoostLifecycleBinding.instance.containerDidShow(container);
// Try to complete pending native result when container closed.
final topPage = topContainer?.topPage.pageInfo.uniqueId ?? "";
assert(topPage != null);
Future.delayed(
const Duration(seconds: 1),
() => _completePendingNativeResultIfNeeded(topPage),
);
}
void _completePendingNativeResultIfNeeded(String initiatorPage) {
_pendingResult.keys
.where((element) => element.startsWith('$initiatorPage#'))
.toList()
.forEach((key) {
_pendingResult[key]!.complete();
_pendingResult.remove(key);
Logger.log('_completePendingNativeResultIfNeeded, '
'key:$key, size:${_pendingResult.length}');
});
}
这里在容器显示时,延迟1秒读取上一个页面返回的数据,并且从_pendingResult中移除了当前容器。
修改建议:
如果发现打开了另一个页面,是否考虑取消延迟事件_completePendingNativeResultIfNeeded。
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the A→B→C navigation sequence described in the issue and inspect onContainerShow and _completePendingNativeResultIfNeeded, especially the delayed one-second completion and _pendingResult removal. Confirm why opening C completes its callback with null, then verify that the B result remains correct and C receives its own result after the fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100