swift - Present flutterViewController and dismiss old rootViewController - Stack Overflow

admin2025-04-18  5

How is the right way to present the flutterViewController if the initial view controller ist another view controller (for example SplashViewController)?

I present the flutterViewController from the SplashViewController (rootViewController):

public class SplashViewController: UIViewController {

   public override func viewDidLoad() {
     super.viewDidLoad()

     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     let flutterEngine = appDelegate.flutterEngine
     let flutterViewController =
     FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
    
  
     flutterViewController.modalPresentationStyle = .overCurrentContext
     flutterViewController.isViewOpaque = false
     appDelegate.window?.rootViewController?.present(flutterViewController, animated: true, completion: nil)

This is working but the flutterViewController is now on the top of the stack of both viewControllers (1. SplashViewController, 2. FlutterViewController).

I ask me if this is the right way or if I have to dismiss the SplashViewController so that there are no problems with other ViewControllers such as MFMailComposeViewController if I open it later from my Flutter app.

Thanks for your help!

转载请注明原文地址:http://www.anycun.com/QandA/1744975676a90281.html