gpt4 book ai didi

ios - 如何让 setInitialRoute 在不同的 View 上启动我的 Flutter iOS 应用程序?

转载 作者:IT王子 更新时间:2023-10-29 06:46:19 24 4
gpt4 key购买 nike

在 flutter 中我有这个:

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

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
routes: <String, WidgetBuilder> {
'/Cards': (BuildContext context) => new PageSelectorDemo(),
},
onGenerateRoute: (RouteSettings settings) => new MaterialPageRoute(
builder: (BuildContext ctx) => new PageSelectorDemo(),
),
theme: new ThemeData(
primarySwatch: Colors.deepPurple,
),
home: new MyHomePage(title: 'Flutter View'),
);
}
}

在我的 iOS 代码中我有这个:

func getFlutterController() -> UIViewController?
{
self.flutterController = FlutterViewController(project: nil, nibName: nil, bundle: nil)

if let controller = self.flutterController
{
controller.setInitialRoute("/Cards") // setting the route
self.messageChannel = FlutterBasicMessageChannel.init(name: "channel", binaryMessenger: controller, codec: FlutterStandardMessageCodec.sharedInstance())
if let channel = self.messageChannel
{
channel.setMessageHandler() { (message:Any?, reply:FlutterReply) in
ViewController.counter += 1
self.labelMessage.text = "message recieved: \(ViewController.counter)"
}
}
}
return self.flutterController
}

为什么这行不通? Flutter 代码仅加载初始 View ,而不是我从“/Cards”路径获取的 View 。

最佳答案

我在从 iOS 设置初始路由时也遇到了问题,看起来它可能是 flutter 中的一个错误: https://github.com/flutter/flutter/issues/27216

关于ios - 如何让 setInitialRoute 在不同的 View 上启动我的 Flutter iOS 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50731093/

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