Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TomasWell opened this issue Jul 26, 2024 · 0 comments

Comments

@TomasWell
Copy link

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

期望返回的时候能销毁

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

有四个页面
原生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

解决方案

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant