Skip to content

Use initWithEngine:nibName:bundle: method to create FlutterViewController, and then setInitialRoute not working #27216

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

Closed
JsouLiang opened this issue Jan 29, 2019 · 44 comments · Fixed by flutter/engine#14367
Labels
a: existing-apps Integration with existing apps via the add-to-app flow engine flutter/engine repository. See also e: labels. f: routes Navigator, Router, and related APIs.

Comments

@JsouLiang
Copy link
Contributor

JsouLiang commented Jan 29, 2019

When I use initWithEngine:nibName:bundle: to create FlutterViewController, and then setInitialRoute: ;I find it doesn't work; When I use window.defaultRouteName in main.dart I get '/'
This is the code:

// Appdelegate

    FlutterEngine *engine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil allowHeadlessExecution:YES];
    self.engine = engine;
    [self.engine runWithEntrypoint:nil];

// ViewController

    FlutterEngine *flutterEngine = [(AppDelegate *)[[UIApplication sharedApplication] delegate] engine];

    FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil];

    [flutterViewController setInitialRoute:@"myApp"];
// main.dart

    void main() => runApp(_widgetForRoute(window.defaultRouteName));

    Widget _widgetForRoute(String route) {
      switch (route) {
        case 'myApp':
          return new MyApp();
        case 'home':
          return new HomePage();
        default:
          return Center(
            child: Text('Unknown route: $route', textDirection: TextDirection.ltr),
          );
      }
    }

I always get a Text and content is ''Unknown route: /'

@kangwang1988
Copy link
Contributor

@x-liang
flutter doctor -v and a minimal demo project which can reproduce this issue would be helpful.

@kangwang1988 kangwang1988 added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 29, 2019
@JsouLiang
Copy link
Contributor Author

https://github.com/X-Liang/NativeWithFlutter This is Demo link

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 29, 2019
@zoechi zoechi added f: routes Navigator, Router, and related APIs. a: existing-apps Integration with existing apps via the add-to-app flow labels Jan 29, 2019
@zoechi zoechi added this to the Goals milestone Jan 29, 2019
@kangwang1988
Copy link
Contributor

kangwang1988 commented Jan 29, 2019

Look like : #23736
I've reproduced this issue using the latest master. It's again a custom engine related problem.

@chengge0921
Copy link

When I use initWithEngine:nibName:bundle: to create FlutterViewController, and then setInitialRoute: ;I find it doesn't work; When I use window.defaultRouteName in main.dart I get '/'
This is the code:

// Appdelegate

    FlutterEngine *engine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil allowHeadlessExecution:YES];
    self.engine = engine;
    [self.engine runWithEntrypoint:nil];

// ViewController

    FlutterEngine *flutterEngine = [(AppDelegate *)[[UIApplication sharedApplication] delegate] engine];

    FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil];

    [flutterViewController setInitialRoute:@"myApp"];
// main.dart

    void main() => runApp(_widgetForRoute(window.defaultRouteName));

    Widget _widgetForRoute(String route) {
      switch (route) {
        case 'myApp':
          return new MyApp();
        case 'home':
          return new HomePage();
        default:
          return Center(
            child: Text('Unknown route: $route', textDirection: TextDirection.ltr),
          );
      }
    }

I always get a Text and content is ''Unknown route: /'

你好,你的这个问题解决了吗?

@zoechi zoechi changed the title Use initWithEngine:nibName:bundle: method to create FlutterViewController, and then setInitialRoute doesn't working Use initWithEngine:nibName:bundle: method to create FlutterViewController, and then setInitialRoute not working Feb 11, 2019
@lupeihong
Copy link

lupeihong commented Feb 13, 2019

I have the same problem

//AppDelegate
self.flutterEngine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil];
[self.flutterEngine runWithEntrypoint:nil];
[GeneratedPluginRegistrant registerWithRegistry:self.flutterEngine];

//ViewController
FlutterViewController *flutterViewController = [FlutterViewController new];
 [flutterViewController setInitialRoute:@"myApp"];


//main.dart
window.defaultRouteName  Is always ‘/’

@zoechi
Copy link
Contributor

zoechi commented Feb 13, 2019

@lupeihong if it's the same problem, why did you create another issue? #27882

@yehot
Copy link

yehot commented Feb 14, 2019

Same problem.

But weird, use FlutterViewController *flutterViewController = [FlutterViewController new]; to init the FlutterViewController , the setInitialRoute work fine.

So what's different between [FlutterViewController new] and [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil] ?

ps:
use FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithProject:nil nibName:nil bundle:nil]; work fine too.

@zoechi
Copy link
Contributor

zoechi commented Feb 19, 2019

@ungacy
Using "add reaction" on the initial comment would increase priority while +1 comments are rather pointless and cause lots of people to get notified for no reason.
To get notified yourself use the [Subscribe] button to the top right instead.

@DavidSonNguyen
Copy link

DavidSonNguyen commented Feb 22, 2019

I use Swift, and i found problem is self.flutterEngine?.run(withEntrypoint: nil) in document https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps. If you do like that, FlutterEngine will run before you create FlutterViewController so you cannot setInitialRoute.
To solve, you must remove that line in AppDelegate, init FlutterViewController without FlutterEngine let flutterViewController = FlutterViewController(nibName: nil, bundle: nil), and setInitialRoute, final call flutterEngine?.run(withEntrypoint: nil).

@youngchan1988

This comment has been minimized.

@zoechi
Copy link
Contributor

zoechi commented Feb 26, 2019

@YoungJam
Using "add reaction" on the initial comment would increase priority while +1 comments are rather pointless and cause lots of people to get notified for no reason.
To get notified yourself use the [Subscribe] button to the top right instead.

@kidzss
Copy link

kidzss commented Mar 6, 2019

I solved the problem.
//=======================

@interface XXFlutterViewController : FlutterViewController

@EnD

(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
FlutterEngine *flutterEngine = self.engine;

[GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
//custom futter plugin
[XXXFlutterBridge registerWithRegistry:flutterEngine];
}

//open flutter vc
XXFlutterViewController *flutterViewController = [[XXFlutterViewController alloc] init];
[flutterViewController setInitialRoute:@"xxxxx/xxxx"];

1 similar comment
@kidzss
Copy link

kidzss commented Mar 6, 2019

I solved the problem.
//=======================

@interface XXFlutterViewController : FlutterViewController

@EnD

(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
FlutterEngine *flutterEngine = self.engine;

[GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
//custom futter plugin
[XXXFlutterBridge registerWithRegistry:flutterEngine];
}

//open flutter vc
XXFlutterViewController *flutterViewController = [[XXFlutterViewController alloc] init];
[flutterViewController setInitialRoute:@"xxxxx/xxxx"];

@ghost
Copy link

ghost commented Mar 6, 2019

it works on me @kidzss

@michealstrong
Copy link

I solved the problem.
//=======================

@interface XXFlutterViewController : FlutterViewController

@EnD

(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
FlutterEngine *flutterEngine = self.engine;

[GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
//custom futter plugin
[XXXFlutterBridge registerWithRegistry:flutterEngine];
}

//open flutter vc
XXFlutterViewController *flutterViewController = [[XXFlutterViewController alloc] init];
[flutterViewController setInitialRoute:@"xxxxx/xxxx"];

Didn't U find the flutterVC dont release in this way?

@michael-chiu
Copy link

I am still experiencing this issue on iOS platform, with the Flutter version shown below :

// --------- flutter doctor summary --------- //

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.3.10, on Mac OS X 10.14 18A391, locale en-HK)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
✗ Verify that all connected devices have been paired with this computer in Xcode.
If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
To update with Brew, run:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
[✓] Android Studio (version 3.3)
[✓] Connected device (3 available)

// --------- flutter doctor summary --------- //

I am following the official guide on https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps.

SetInitialRoute() is working when using FlutterViewController(project: nil, nibName: nil, bundle: nil), however, this seems make the Flutter plugins not found with the FlutterViewController, when I try to access methods in Flutter plugins, it throws MissingPluginException. It seems that because of those Plugins are register with FlutterEngine, the FlutterViewController will not find them if not connected with the FlutterEngine.

Using FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil), makes the plugins work, but SetInitialRoute() is not working.

Is there any way or alternative to solve this issue, making both setInitialRoute and plugins work in the same FlutterViewController? Thanks!

@Lolingew
Copy link

I solved the problem.
//=======================
@interface XXFlutterViewController : FlutterViewController
@EnD
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
FlutterEngine *flutterEngine = self.engine;
[GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
//custom futter plugin
[XXXFlutterBridge registerWithRegistry:flutterEngine];
}
//open flutter vc
XXFlutterViewController *flutterViewController = [[XXFlutterViewController alloc] init];
[flutterViewController setInitialRoute:@"xxxxx/xxxx"];

Didn't U find the flutterVC dont release in this way?

I meet the problem... almost nothing released...

@yxwandroid
Copy link

When I use initWithEngine:nibName:bundle: to create FlutterViewController, and then setInitialRoute: ;I find it doesn't work; When I use window.defaultRouteName in main.dart I get '/'
This is the code:

// Appdelegate

    FlutterEngine *engine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil allowHeadlessExecution:YES];
    self.engine = engine;
    [self.engine runWithEntrypoint:nil];

// ViewController

    FlutterEngine *flutterEngine = [(AppDelegate *)[[UIApplication sharedApplication] delegate] engine];

    FlutterViewController* flutterViewController = [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil];

    [flutterViewController setInitialRoute:@"myApp"];
// main.dart

    void main() => runApp(_widgetForRoute(window.defaultRouteName));

    Widget _widgetForRoute(String route) {
      switch (route) {
        case 'myApp':
          return new MyApp();
        case 'home':
          return new HomePage();
        default:
          return Center(
            child: Text('Unknown route: $route', textDirection: TextDirection.ltr),
          );
      }
    }

I always get a Text and content is ''Unknown route: /'
我遇到同样的问题 请问你解决了吗

@kidzss
Copy link

kidzss commented May 13, 2019

I solved the problem.
//=======================
@interface XXFlutterViewController : FlutterViewController
@EnD
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
FlutterEngine *flutterEngine = self.engine;
[GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
//custom futter plugin
[XXXFlutterBridge registerWithRegistry:flutterEngine];
}
//open flutter vc
XXFlutterViewController *flutterViewController = [[XXFlutterViewController alloc] init];
[flutterViewController setInitialRoute:@"xxxxx/xxxx"];

Didn't U find the flutterVC dont release in this way?

I meet the problem... almost nothing released...
我使用flutter 1.2.1 在dealloc断点是有的

@ghost
Copy link

ghost commented May 13, 2019

I solved the problem.
//=======================
@interface XXFlutterViewController : FlutterViewController
@EnD
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
FlutterEngine *flutterEngine = self.engine;
[GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
//custom futter plugin
[XXXFlutterBridge registerWithRegistry:flutterEngine];
}
//open flutter vc
XXFlutterViewController *flutterViewController = [[XXFlutterViewController alloc] init];
[flutterViewController setInitialRoute:@"xxxxx/xxxx"];

Didn't U find the flutterVC dont release in this way?

I meet the problem... almost nothing released...
我使用flutter 1.2.1 在dealloc断点是有的

i use the same solution and it fixed.But official should also give a solution.

@Lolingew
Copy link

I solved the problem.
//=======================
@interface XXFlutterViewController : FlutterViewController
@EnD
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
FlutterEngine *flutterEngine = self.engine;
[GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
//custom futter plugin
[XXXFlutterBridge registerWithRegistry:flutterEngine];
}
//open flutter vc
XXFlutterViewController *flutterViewController = [[XXFlutterViewController alloc] init];
[flutterViewController setInitialRoute:@"xxxxx/xxxx"];

Didn't U find the flutterVC dont release in this way?

I meet the problem... almost nothing released...
我使用flutter 1.2.1 在dealloc断点是有的

I update 1.2.1 last week. Do you mean, at 1.2.1 version, this solution will release memory normally? I used this before and found memory increased linearly. I'll try 1.2.1 and test it.

@zhangyihui-whalevii
Copy link

WVFlutterViewController *controller = [[WVFlutterViewController alloc] init];
[GeneratedPluginRegistrant registerWithRegistry:controller];
[controller setInitialRoute:route];

使用这种方式可以成功传递route,并且不会影响插件的注册

@ly05010419
Copy link

the same Problem!

@hucong730
Copy link

WVFlutterViewController *controller = [[WVFlutterViewController alloc] init];
[GeneratedPluginRegistrant registerWithRegistry:controller];
[controller setInitialRoute:route];

使用这种方式可以成功传递route,并且不会影响插件的注册

这个方式有效果,感谢。

@zzjjob
Copy link

zzjjob commented Sep 11, 2019

  1. create FlutterEngine
  2. [_engine.get() createShell:nil libraryURI:nil];
    [_engine.navigationChannel invokeMethod:@"setInitialRoute" arguments:route];
  3. self.flutterVc = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
    [engine launchEngine:nil libraryURI:nil];
    [engine setViewController:self.flutterVc];

@binjiayou66
Copy link

I solved the problem.
//=======================
@interface XXFlutterViewController : FlutterViewController
@EnD
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
FlutterEngine *flutterEngine = self.engine;
[GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
//custom futter plugin
[XXXFlutterBridge registerWithRegistry:flutterEngine];
}
//open flutter vc
XXFlutterViewController *flutterViewController = [[XXFlutterViewController alloc] init];
[flutterViewController setInitialRoute:@"xxxxx/xxxx"];

Didn't U find the flutterVC dont release in this way?

I meet the problem... almost nothing released...
我使用flutter 1.2.1 在dealloc断点是有的

i use the same solution and it fixed.But official should also give a solution.

Creating a new FlutterViewController in the new or alloc init way does deliver routeName, but this way creates multiple flutter.io/gpu/ui threads over and over again.

@Aronlong1001
Copy link

I am still experiencing this issue on iOS platform, with the Flutter version shown below :

// --------- flutter doctor summary --------- //

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.3.10, on Mac OS X 10.14 18A391, locale en-HK)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
✗ Verify that all connected devices have been paired with this computer in Xcode.
If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
To update with Brew, run:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
[✓] Android Studio (version 3.3)
[✓] Connected device (3 available)

// --------- flutter doctor summary --------- //

I am following the official guide on https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps.

SetInitialRoute() is working when using FlutterViewController(project: nil, nibName: nil, bundle: nil), however, this seems make the Flutter plugins not found with the FlutterViewController, when I try to access methods in Flutter plugins, it throws MissingPluginException. It seems that because of those Plugins are register with FlutterEngine, the FlutterViewController will not find them if not connected with the FlutterEngine.

Using FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil), makes the plugins work, but SetInitialRoute() is not working.

Is there any way or alternative to solve this issue, making both setInitialRoute and plugins work in the same FlutterViewController? Thanks!

i have the same question, have you solved it, please?

@lyc2345
Copy link

lyc2345 commented Oct 16, 2019

I am still experiencing this issue on iOS platform, with the Flutter version shown below :
// --------- flutter doctor summary --------- //
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.3.10, on Mac OS X 10.14 18A391, locale en-HK)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
✗ Verify that all connected devices have been paired with this computer in Xcode.
If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
To update with Brew, run:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
[✓] Android Studio (version 3.3)
[✓] Connected device (3 available)
// --------- flutter doctor summary --------- //
I am following the official guide on https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps.
SetInitialRoute() is working when using FlutterViewController(project: nil, nibName: nil, bundle: nil), however, this seems make the Flutter plugins not found with the FlutterViewController, when I try to access methods in Flutter plugins, it throws MissingPluginException. It seems that because of those Plugins are register with FlutterEngine, the FlutterViewController will not find them if not connected with the FlutterEngine.
Using FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil), makes the plugins work, but SetInitialRoute() is not working.
Is there any way or alternative to solve this issue, making both setInitialRoute and plugins work in the same FlutterViewController? Thanks!

i have the same question, have you solved it, please?

When you create a FlutterViewController don't use FlutterEngine

let flutterViewController = FlutterViewController(nibName: nil, bundle: nil)
flutterVC.setInitialRoute("RouteName")

Use this way is working!

@xx-li
Copy link

xx-li commented Oct 31, 2019

I use [FlutterViewController new] replace [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil]setInitialRoute is working, but when native push this FlutterViewController firsh show splashScreen。 Anyone encounter the same problem,how to avoid show splashScreen?

my env is :

Xcode11.2 / iOS13 
Flutter 1.10.14 • channel dev • https://github.com/flutter/flutter.git
Framework • revision 1946fc4da0 (3 weeks ago) • 2019-10-07 15:23:31 -0700
Engine • revision 1d62160fdb
Tools • Dart 2.6.0 (build 2.6.0-dev.1.0 d6c6d12ebf)

@ungacy
Copy link

ungacy commented Nov 1, 2019

I use [FlutterViewController new] replace [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil]setInitialRoute is working, but when native push this FlutterViewController firsh show splashScreen。 Anyone encounter the same problem,how to avoid show splashScreen?

my env is :

Xcode11.2 / iOS13 
Flutter 1.10.14 • channel dev • https://github.com/flutter/flutter.git
Framework • revision 1946fc4da0 (3 weeks ago) • 2019-10-07 15:23:31 -0700
Engine • revision 1d62160fdb
Tools • Dart 2.6.0 (build 2.6.0-dev.1.0 d6c6d12ebf)

try to set a view to propertysplashScreenView to the instance of FlutterViewController

@xx-li
Copy link

xx-li commented Nov 1, 2019

I use [FlutterViewController new] replace [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil]setInitialRoute is working, but when native push this FlutterViewController firsh show splashScreen。 Anyone encounter the same problem,how to avoid show splashScreen?
my env is :

Xcode11.2 / iOS13 
Flutter 1.10.14 • channel dev • https://github.com/flutter/flutter.git
Framework • revision 1946fc4da0 (3 weeks ago) • 2019-10-07 15:23:31 -0700
Engine • revision 1d62160fdb
Tools • Dart 2.6.0 (build 2.6.0-dev.1.0 d6c6d12ebf)

try to set a view to propertysplashScreenView to the instance of FlutterViewController

tks,I am so tried,push animation is not normal

@ungacy
Copy link

ungacy commented Nov 1, 2019

    FlutterViewController *some = [FlutterViewController new];
    UIView *view = [[UIView alloc] initWithFrame:UIApplication.sharedApplication.keyWindow.bounds];
    view.backgroundColor = [UIColor whiteColor];
    some.splashScreenView = view;

@xx-li
Copy link

xx-li commented Nov 1, 2019

    FlutterViewController *some = [FlutterViewController new];
    UIView *view = [[UIView alloc] initWithFrame:UIApplication.sharedApplication.keyWindow.bounds];
    view.backgroundColor = [UIColor whiteColor];
    some.splashScreenView = view;

tks, I am also try so, push animation firsh show white splashScreenView, I need to avoid show splashScreen.

@zyg1982527
Copy link

我搞定了,可以传入routeName,又能保证交互好用。it work well

let flutterViewController = FlutterViewController.init(project: nil , nibName: nil, bundle: nil)!;
flutterViewController.splashScreenView = FlutterSplashViewController().view
GeneratedPluginRegistrant.register(with: flutterViewController)
flutterViewController.setInitialRoute("test1");
flutterViewController.view.frame = UIScreen.main.bounds;
self.navigationController?.pushViewController(flutterViewController, animated: true)
self.flutterEngine = FlutterEngine(name: "io.flutter", project: nil)
self.flutterEngine?.run(withEntrypoint: nil)
GeneratedPluginRegistrant.register(with: self.flutterEngine)

@xx-li
Copy link

xx-li commented Nov 4, 2019

Use [FlutterViewController new] replace [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil] cause other problems。 I have two problems encountered now.

  1. Can't avoid show splashScreenView
  2. Case package_info not normal work。 (Suspected that the native and Flutter could not communicate properly)

@zyg1982527
Copy link

zyg1982527 commented Nov 4, 2019 via email

@xx-li
Copy link

xx-li commented Nov 4, 2019

@zyg1982527 Should be caused by plugin registration issues, use [GeneratedPluginRegistrant registerWithRegistry:flutterViewController]; after FlutterViewController init can resolve it。 A little worried about whether other problems will be introduced later。

@freedom-shen
Copy link

freedom-shen commented Nov 14, 2019

仔细研究了下Flutter/Engine里面的源码,setInitialRoute要在launchEngine:libraryURI:之前,
使用了initWithEngine方法,要求自定义的FlutterEngine初始化完毕,并且运行runWithEntrypoint:libraryURI:(内部还是会调用launchEngine:libraryURI:)。
所以使用initWithEngine初始化,setInitialRoute是无效的。
所以只能使用initWithProject(init,new都会调用该方法),但是带来了新问题会加载Launch图。

贴一个简单的思路,新建一个FlutterViewController的子类CSFlutterController,去除和launch有关的部分。

@interface CSFlutterViewController ()  {
    BOOL _enigneNeedsLaunch;
}
@end

@implementation CSFlutterViewController

#pragma mark - Rewrite

- (BOOL)loadDefaultSplashScreenView {
    return NO;
}

- (void)installSplashScreenViewIfNecessary {
}

- (void)removeSplashScreenView:(dispatch_block_t _Nullable)onComplete {
    onComplete();
}

#pragma mark - Init Rewrite

- (instancetype)initWithProject:(FlutterDartProject *)project nibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
    self = [super initWithProject:project nibName:nibName bundle:nibBundle];
    if (self) {
        _enigneNeedsLaunch = NO;
        [self setInitialRoute:@"/userCenter"];
        [self.engine performSelector:@selector(launchEngine:libraryURI:) withObject:nil withObject:nil];
        [self.engine runWithEntrypoint:nil libraryURI:nil];
        [self.engine setViewController:self];
    }
    return self;
}

@end

@amazingrace
Copy link

WVFlutterViewController *controller = [[WVFlutterViewController alloc] init];
[GeneratedPluginRegistrant registerWithRegistry:controller];
[controller setInitialRoute:route];

使用这种方式可以成功传递route,并且不会影响插件的注册

Yes, it woks for me. You saved my 2 days time, thanks a lot.

亲们,这个法子真的可以啊,[GeneratedPluginRegistrant registerWithRegistry:controller]; 而不是[GeneratedPluginRegistrant registerWithRegistry:self.engine];
官网害死人啦。
---------来自被这个问题搞疯了两天的程序媛。。

@zyg1982527
Copy link

zyg1982527 commented Nov 19, 2019 via email

@xster
Copy link
Member

xster commented Dec 11, 2019

This is somewhat the same as #31185 and now covered under #31185. Also adding some clarifications in flutter/engine#14367.

To be fair, this API is indeed unclear and confusing. I think we want to gradually discourage its use but don't have a great alternative yet.

In general, we should make all custom interop easier #32930 so you can pass any initialization data you'd like at startup, not only route.

Also, if we were to make built-in concepts like route easier, we should do it on top of the upcoming navigator APIs rather than adding more to the current imperative navigator APIs. #45938

@WinJayQ
Copy link

WinJayQ commented Jan 7, 2020

I use Swift, and i found problem is self.flutterEngine?.run(withEntrypoint: nil) in document https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps. If you do like that, FlutterEngine will run before you create FlutterViewController so you cannot setInitialRoute.
To solve, you must remove that line in AppDelegate, init FlutterViewController without FlutterEngine let flutterViewController = FlutterViewController(nibName: nil, bundle: nil), and setInitialRoute, final call flutterEngine?.run(withEntrypoint: nil).

Yes, it woks for me.

@jitesh-sharma
Copy link

jitesh-sharma commented Jan 14, 2020

I use Swift, and i found problem is self.flutterEngine?.run(withEntrypoint: nil) in document https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps. If you do like that, FlutterEngine will run before you create FlutterViewController so you cannot setInitialRoute.
To solve, you must remove that line in AppDelegate, init FlutterViewController without FlutterEngine let flutterViewController = FlutterViewController(nibName: nil, bundle: nil), and setInitialRoute, final call flutterEngine?.run(withEntrypoint: nil).

Yes, it woks for me.

its working, but showing splash screen before pushing to flutterViewController and when we are trying to pop from flutterViewController its pop to black screen instead of our native iOS ViewController. Also we have another issue when we create flutterView without flutterengine like getting MissingPluginException for FlutterMethodChannel.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: existing-apps Integration with existing apps via the add-to-app flow engine flutter/engine repository. See also e: labels. f: routes Navigator, Router, and related APIs.
Projects
None yet