简体   繁体   中英

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. 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. 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. and it returns error

'package:flutter/src/widgets/framework.dart': Failed assertion: line 5334 pos 14: '_dependents.isEmpty': is not true.

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(
 /*...*/
   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,

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.

Even if you integrate one or more apps into another app, there must be only one main after the whole merge.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM