flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.65k stars 27.35k forks source link

setInitialRoute broken on iOS #18500

Closed sigurdm closed 6 years ago

sigurdm commented 6 years ago

The isolate is running already when the init-method on FlutterViewController is done running. There is no time to set the route.

This seems to have happened as part of https://github.com/flutter/engine/commit/58e84c8bf0b6304649340e6eaad988602961d7f6

Before engine connection was made in -viewWillAppear leaving time for the initial route to be set: https://github.com/flutter/engine/commit/58e84c8bf0b6304649340e6eaad988602961d7f6#diff-366c592b71736b6c5519e04346bf325cL339

Moving

    // Launch the Dart application with the inferred run configuration.
    _shell->GetTaskRunners().GetUITaskRunner()->PostTask(
        fxl::MakeCopyable([engine = _shell->GetEngine(),                   //
                           config = [_dartProject.get() runConfiguration]  //
    ]() mutable {
          if (engine) {
            auto result = engine->Run(std::move(config));
            if (!result) {
              FXL_LOG(ERROR) << "Could not launch engine with configuration.";
            }
          }
        }));

from -setupShell to -viewWillAppear seems to solve the issue...

cc @chinmaygarde

kidzss commented 5 years ago

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"];

github-actions[bot] commented 3 years ago

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.