[英]Integrate a Flutter app in to another flutter app
I have a bigger app named X and I have another smaller one named Y. they are right now separate from each other and they are working fine.我有一个名为 X 的较大应用程序,还有另一个名为 Y 的较小应用程序。它们现在彼此分开并且工作正常。 I want to integrate app Y in X. I want to put codes of Y in X project but they should have a different Main so I can set different themes and routes.我想将应用 Y 集成到 X 中。我想将 Y 的代码放入 X 项目中,但它们应该有不同的 Main 以便我可以设置不同的主题和路线。 Is there anyway to do that?有没有办法做到这一点?
////update//// ////更新////
I upvoted all answers because they are all correct.我赞成所有答案,因为它们都是正确的。
but if you know this one please answer.但如果你知道这个,请回答。 I am using GetMaterialApp from GetX instead of MaterialApp.我正在使用 GetX 的 GetMaterialApp 而不是 MaterialApp。 and it returns error它返回错误
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5334 pos 14: '_dependents.isEmpty': is not true. 'package:flutter/src/widgets/framework.dart':断言失败:第 5334 行 pos 14:'_dependents.isEmpty':不正确。
how can I fix this?我怎样才能解决这个问题?
You can use multiple MaterialApp()
in your project, combine the code/file like that the app is on another screen, and you will result in apps that have different references to their InheritedWidget
s like Theme
, Navigator
, MediaQuery
...您可以在您的项目中使用多个MaterialApp()
,组合代码/文件,就像应用程序在另一个屏幕上一样,您将导致应用程序对其InheritedWidget
有不同的引用,例如Theme
, Navigator
, MediaQuery
...
/*...*/
MaterialApp(
/*...*/
home: AppXHome(),
),
/*...*/
class AppXHome extends StatelessWidegt {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(),
Container(),
MaterialApp(
home: AppYHome(),
),
],
),}}
You can use two MaterialApp widgets for defining separate routing, One for your APP X and other for Your APP Y, Main function will remain the same no changes needed,您可以使用两个 MaterialApp 小部件来定义单独的路由,一个用于您的 APP X,另一个用于您的 APP Y,Main function 将保持不变,无需更改,
just create a route in APP X for app Y and wrap your App Y code in another MaterialApp Widget where you can define routes for APP Y.只需在 APP X 中为应用程序 Y 创建一个路由,并将您的应用程序 Y 代码包装在另一个 MaterialApp 小部件中,您可以在其中为应用程序 Y 定义路由。
Even if you integrate one or more apps into another app, there must be only one main
after the whole merge.即使你将一个或多个应用集成到另一个应用中,整个合并后也必须只有一个main
。
So you need to move the other's main logic to the current one and then deal with the theme.所以需要把对方的主要逻辑移到当前的,再处理主题。
You can utilize this sample , which has three different apps in it with custom themes您可以利用此示例,其中包含三个带有自定义主题的不同应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.