颤振材料路线不';t在本机iOS navigatorViewController上导航

颤振材料路线不';t在本机iOS navigatorViewController上导航,ios,objective-c,swift,flutter,Ios,Objective C,Swift,Flutter,我已经使用颤振部分的颤振方法通道调用打开了本机故事板UIViewController。现在我想使用iOS(swift)部分的方法调用导航到其他小部件/视图。 方法调用和路由部分没有问题,只有一个问题。我通过iOS代码中的invokeMethod从颤振部分导航到的新视图已包含在当前iOS视图中。这就是我从颤振方法“wait platform.invokeMethod('Printy');”打开的iOS UIViewController下的新颤振导航小部件。我想在当前iOS UIViewContro

我已经使用颤振部分的颤振方法通道调用打开了本机故事板UIViewController。现在我想使用iOS(swift)部分的方法调用导航到其他小部件/视图。 方法调用和路由部分没有问题,只有一个问题。我通过iOS代码中的invokeMethod从颤振部分导航到的新视图已包含在当前iOS视图中。这就是我从颤振方法“wait platform.invokeMethod('Printy');”打开的iOS UIViewController下的新颤振导航小部件。我想在当前iOS UIViewController上导航

AppDelegate.swift

@objc class AppDelegate: FlutterAppDelegate {
    var navigationController: UINavigationController?
    var CHANNEL: FlutterMethodChannel?
    
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        let controller = window.rootViewController as! FlutterViewController
        CHANNEL = FlutterMethodChannel(name: "com.flutter.epic/epic", binaryMessenger: controller as! FlutterBinaryMessenger)
        CHANNEL?.setMethodCallHandler { [unowned self] (methodCall, result) in
            if methodCall.method == "Printy" {
                self.newViewController(result)
            }
        }

        GeneratedPluginRegistrant.register(with: self)
        
        navigationController = UINavigationController(rootViewController: controller)
        navigationController?.isNavigationBarHidden = true
        window?.rootViewController = navigationController
        window?.makeKeyAndVisible()
        
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    func newViewController(_ result: @escaping FlutterResult) {
        let storyboard : UIStoryboard? = UIStoryboard.init(name: "Main", bundle: nil);
        let window: UIWindow = ((UIApplication.shared.delegate?.window)!)!
        let paytmTransactionController = storyboard!.instantiateViewController(withIdentifier: "PaytmTransactionController") as! PaytmTransactionController
        paytmTransactionController.result = result
        self.navigationController?.pushViewController(paytmTransactionController, animated: true)
    }
}
PaytmTransactionController.swift

class PaytmTransactionController: UIViewController {
    var result: FlutterResult?
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    @IBAction func close(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }
    
    @IBAction func showFlutterView(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
        (UIApplication.shared.delegate as? AppDelegate)!.CHANNEL!.invokeMethod("didRecieveTranscript", arguments: nil)
    }
}
颤振->应用程序省道

class AppState extends State<App> {
final GlobalKey<NavigatorState> navigatorKey =
    new GlobalKey<NavigatorState>();

@override
void initState() {
  super.initState();

  final channelName = 'com.flutter.epic/epic';
  final methodChannel = MethodChannel(channelName);
  methodChannel.setMethodCallHandler(this._didRecieveTranscript);
}

Future<void> _didRecieveTranscript(MethodCall call) async {
  final String utterance = call.arguments;
  switch (call.method) {
    case "didRecieveTranscript":
      openMyProject(utterance);
      break;
    case "didRecieveNativeViewFactory":
      didRecieveNativeViewFactory(utterance);
      break;
  }
}

Future<void> didRecieveNativeViewFactory(utterance) async {
  navigatorKey.currentState
      .pushNamed("/project", arguments: ScreenArguments());
}

Future<void> openMyProject(utterance) async {
  navigatorKey.currentState
      .pushNamed("/project", arguments: ScreenArguments());
}

@override
Widget build(BuildContext context) {
  // TODO: implement build
  if (this._locale == null) {
    return CircularProgressIndicator();
  } else {
    return Provider(
      create: (context) => ApiService.create(),
      child: ZoningProvider(
        child: GlobalProvider(
          child: DashboardProvider(
            child: AuthProvider(
              child: MaterialApp(
                title: GlobalVariable.appTitle,
                theme: ThemeData(
                    //fontFamily: FontClass.defaultRegular,
                    ),
                onGenerateRoute: RouterClass().router,
                navigatorKey: navigatorKey,
                supportedLocales: [
                  Locale('en', 'US'),
                  Locale('zh', 'Chinese'),
                ],
                localizationsDelegates: [
                  AppLocalizations.delegate,
                  GlobalWidgetsLocalizations.delegate,
                  GlobalMaterialLocalizations.delegate,
                ],
                localeResolutionCallback: (locale, supportedLocales) {
                  for (var supportedLocale in supportedLocales) {
                    if (supportedLocale.languageCode == locale.languageCode &&
                        supportedLocale.countryCode == locale.countryCode) {
                      return supportedLocale;
                    }
                  }
                  return supportedLocales.first;
                },
                locale: _locale,
              ),
            ),
          ),
        ),
      ),
    );
  }
}
类AppState扩展状态{
最后的环球航空公司=
新GlobalKey();
@凌驾
void initState(){
super.initState();
最终通道名='com.flutter.epic/epic';
最终方法通道=方法通道(通道名称);
methodChannel.setMethodCallHandler(此._diReceiveTranscript);
}
Future\u DiReceiveTranscript(MethodCall调用)异步{
最终字符串发音=call.arguments;
开关(调用方法){
案例“DidReceiveTranscript”:
openMyProject(话语);
打破
案例“DidReceiveEviewFactory”:
DidReceiveEviewFactory(话语);
打破
}
}
Future DidReceiveEviewFactory(语音)异步{
navigatorKey.currentState
.pushNamed(“/project”,参数:ScreenArguments());
}
未来openMyProject(语音)异步{
navigatorKey.currentState
.pushNamed(“/project”,参数:ScreenArguments());
}
@凌驾
小部件构建(构建上下文){
//TODO:实现构建
if(this.\u locale==null){
返回循环ProgressIndicator();
}否则{
返回提供者(
create:(context)=>ApiService.create(),
子:分区提供程序(
儿童:环球旅行社(
子:仪表板提供程序(
子:AuthProvider(
孩子:MaterialApp(
标题:GlobalVariable.appTitle,
主题:主题数据(
//fontFamily:FontClass.defaultRegular,
),
onGenerateRoute:RouterClass()。路由器,
导航工作:导航工作,
支持的区域设置:[
地区('en','US'),
地区('zh','Chinese'),
],
本地化授权:[
AppLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalMaterialAllocalizations.delegate,
],
localeResolutionCallback:(locale,supportedLocales){
for(supportedLocales中的var supportedLocale){
如果(supportedLocale.languageCode==locale.languageCode&&
supportedLocale.countryCode==locale.countryCode){
返回支持的语言环境;
}
}
返回supportedLocales.first;
},
地区:_地区,
),
),
),
),
),
);
}
}

}经过两天的探索,我找到了一个解决方案。很简单,只需调用“SystemNavigator.pop()”即可从颤振端弹出iOS路由