alibaba / alibaba/flutter_boost

[Bug]: iOS原生跳转flutter页面,每次都是一个新的Flutter页,且来回进入和退出,第一个页面一直存在

Open
#2,098 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
7.2k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

### 请描述遇到的问题,以及您所期望的正确的结果

期望返回的时候能销毁

### 请说明如何操作会遇到上述问题

有四个页面
原生A、FlutterB、原生C、FlutterD
/course-category-page就是FlutterB页面

ABCD DCBA ABCD DCBA ABCD DCBA ABCD DCBA
来来回回进入和退出

控制台会打印
2024-07-26 15:29:37.244258+0800 中华珍宝馆[9823:584279] flutter: FlutterBoost_dart#remove, uniqueId=94B54E17-A0D4-4746-8C5A-0F72E5481934,
[
BoostContainer(name:/, pages:[BoostPage(name:/, uniqueId:1721978793456_/, arguments:null)]), BoostContainer(name:/course-category-page, pages:[BoostPage(name:/course-category-page, uniqueId:0E0C5626-EC8B-4F3E-A054-1B03783082AF, arguments:{})]),
BoostContainer(name:/course-category-page, pages:[BoostPage(name:/course-category-page, uniqueId:4EC89038-9298-45B9-9A12-96D27CE1C7C8, arguments:{})]),
BoostContainer(name:/course-category-page, pages:[BoostPage(name:/course-category-page, uniqueId:18C936E5-B26E-4AD8-9AB3-024D2E7B7DA6, arguments:{})]),
BoostContainer(name:/course-category-page, pages:[BoostPage(name:/course-category-page, uniqueId:49466E7A-1EF0-4F48-A6F8-285AE7CFC9F0, arguments:{})]),
BoostContainer(name:/course-category-page, pages:[BoostPage(name:/course-category-page, uniqueId:5E0E4454-2189-455D-812E-0254D1E265FA, arguments:{})]),
BoostContainer(name:/course-category-page, pages:[BoostPage(name:/course-category-page, uniqueId:47AAF476-7376-4AA8-B983-FD5CEC12E612, arguments:{})]),
BoostContainer(name:/course-category-page, pages:[BoostPage(name:/course-category-page, uniqueId:9FB0A364-84C6-4E97-B241-974E36A52F9D, arguments:{})]),
BoostContainer(name:/course-category-page, pages:[BoostPage(name:/course-category-page, uniqueId:9B437F25-E172-4FE5-B4CE-DE3BC2D92FD9, arguments:{})])]

每一个uniqueId都不一样,是不是对应的就是B页面初始化了很多

这是问题1

问题2是,当C页面是个嵌套Flutter的原生页面的时候,按照上面来回操作,B页面会白屏

### 在下面填入关键复现代码

```
```
**原生进入Flutter代码如下**
- (void)goFlutterWithPageName:(NSString *)pageName arguments:(NSDictionary *)arguments {
FlutterBoostRouteOptions *options = [[FlutterBoostRouteOptions alloc] init];
options.pageName = pageName;
// options.uniqueId = nil;
options.arguments = arguments;
options.onPageFinished = ^(NSDictionary * dic) {
NSLog(@"onPageFinished 反向传值");//反向传值
NSLog(@"%@",dic);//反向传值
};
options.completion = ^(BOOL success) {
return;//跳转完成的回调
};
[[FlutterBoost instance] open:options];
}

**Flutter页面pop**
- (void)popRoute:(FlutterBoostRouteOptions *)options {
ARTFlutterViewController *vc = (id)self.navigationController.presentedViewController;
BOOL animated = YES;
NSNumber * animatedValue = options.arguments[@"animated"];
if(animatedValue){
animated = [animatedValue boolValue];
}
if([vc isKindOfClass:ARTFlutterViewController.class] && [vc.uniqueIDString isEqual: options.uniqueId]){
if(vc.modalPresentationStyle == UIModalPresentationOverFullScreen){
[self.navigationController.topViewController beginAppearanceTransition:YES animated:NO];
[vc dismissViewControllerAnimated:YES completion:^{
[self.navigationController.topViewController endAppearanceTransition];
}];
}else{
[vc dismissViewControllerAnimated:YES completion:^{}];
}
}else{
[self.navigationController popViewControllerAnimated:animated];
}
if (self.onPageFinished) {
self.onPageFinished(options.arguments);
}
options.completion(YES);
}

**原生页面嵌套Flutter页面代码如下**
- (void)dealloc {
[self stopTimer];
[self.flutterViewController notifyWillDealloc];
[self.flutterViewController detachFlutterEngineIfNeeded];
}

- (void)initView {
self.rt_disableInteractivePop = NO;
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[self.view addSubview:self.mainView];
[self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
}];

[self initViewAction];
[self initFlutterView];
}

- (void)initFlutterView {
self.flutterViewController = [[ARTFlutterViewController alloc] init];
NSString *routePath = [NSString stringWithFormat:@"/%@",self.page];
[self.flutterViewController setName:routePath uniqueId:nil params:@{@"id":self.id_p} opaque:YES];
[self addChildViewController:self.flutterViewController];

[self.mainView.businessContainer addSubview:self.flutterViewController.view];
CGRect containerFrame = self.mainView.businessContainer.frame;
self.flutterViewController.view.frame = CGRectMake(0, 0, containerFrame.size.width, containerFrame.size.height);
}

### 复现的平台

iOS

### Flutter SDK版本

3.19.6

### FlutterBoost版本

5.0.2

### 是否延迟初始化FlutterBoost

No

### 解决方案

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the native entry points goFlutterWithPageName:arguments:, popRoute:, and initFlutterView, then reproduce the repeated ABCD/DCBA navigation sequence on iOS. Inspect the logged FlutterBoost containers and unique IDs, including the nested Flutter case. Done means returning from Flutter removes the prior page instances and repeated navigation no longer leaves B white.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, ios, objective-c
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.