How can I "push" a UIViewController from FlutterViewController

Question

Asked by Eason P on August 12, 2017 (source).

I want to "push" a new native view (Activity as in Android & UIViewController as in iOS) upon our Flutter view, and after that new native view is completed/finished, make screen come back to our Flutter view.

I can do this in Android. But I'm very new to iOS, when I try to do this in ios/Runner/AppDelegate.m:

  SwiftViewController *swiftViewController = [controller.storyboard instantiateViewControllerWithIdentifier:@"SwiftViewController"];
  [(FlutterViewController *)self.window.rootViewController pushViewController:swiftViewController animated:YES];

It gives error:

No visible @interface for "FlutterViewController" declared the selector 'pushViewController:animated'

So how to do it in iOS? Thanks

Answer

Question answered by German S (source).

You need to embed FlutterViewController in container UINavigationController programmatically or in storyboard, then you will be able to push your next controller.

Here is example how to embed programmatically:

@interface AppDelegate()
@property (nonatomic, strong) UINavigationController *navigationController;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];

  UIViewController *flutterViewController = [[FlutterViewController alloc] init];
  self.navigationController = [[UINavigationController alloc] initWithRootViewController:flutterViewController];
  [self.navigationController setNavigationBarHidden:YES];

  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  self.window.rootViewController = self.navigationController;
  [self.window makeKeyAndVisible];

  return true;
}

- (void)pushExample {
  UIViewController *viewController = [[UIViewController alloc] init];
  [self.navigationController pushViewController:viewController animated:true];
}

@end

When needed(e.g. button tapped) invoke pushExample. Also you can check "storyboard" way in this video

FLUTTER IOS UIVIEWCONTROLLER
SHARE: