gpt4 book ai didi

ios - 如何从原生 iOS 设置初始路由

转载 作者:行者123 更新时间:2023-12-01 17:03:24 25 4
gpt4 key购买 nike

我将 Flutter 模块集成到 ios Native 项目中,我想从 ios Native 设置 Initial Route,但它不起作用,它使用默认路由。

ViewController.swift

import UIKit
import Flutter

class ViewController: UIViewController {

let flutterEngine = FlutterEngine(name: "test")

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
flutterEngine.navigationChannel.invokeMethod("setInitialRoute", arguments:"/home")
flutterEngine.run();

}

@IBAction func handleClick(_ sender: Any) {
let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
flutterViewController.setInitialRoute("/home")
self.navigationController?.pushViewController(flutterViewController, animated: true)
}

}

主要.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
final _route = <String, WidgetBuilder>{
"/login": (context) => Login(),
"/home": (context) => Home()
};

@override
Widget build(BuildContext context) {
return MaterialApp(
routes: _route,
title: "App", // Title ของหน้า
home: Scaffold(
// หน้าจอหลัก
appBar: AppBar(
title: Text("App Navi"),
),
body: Login(),
),
);
}
}

登录,主页文件请看图片,因为stackoverflow不能发布文本“看起来你的帖子主要是代码;请添加更多细节。”

enter image description here

enter image description here

enter image description here

enter image description here

最佳答案

此问题现已修复,自 起 flutter 1.22 可以使用:
在初始化 flutter 引擎时:

let flutterEngine = FlutterEngine()
// FlutterDefaultDartEntrypoint is the same as nil, which will run main().
engine.run(
withEntrypoint: FlutterDefaultDartEntrypoint, initialRoute: "/onboarding")
并且,直接在创建 FlutterViewController 时,
 let flutterViewController = FlutterViewController(
project: nil,
initialRoute: "/onboarding",
nibName: nil,
bundle: nil)

关于ios - 如何从原生 iOS 设置初始路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61052776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com