Home > other >  Integrate a Flutter app in to another flutter app
Integrate a Flutter app in to another flutter app

Time:11-23

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?

CodePudding user response:

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 InheritedWidgets 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(),
     ),
    ],
   ),}}

CodePudding user response:

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.

CodePudding user response:

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

  • Related