How to import flutter module/Project with another flutter project

Sayed
2 min readNov 24, 2023

--

Use case:

Imagine you’ve developed a fully functional and operational e-commerce app named ABC. After a few days, your client approaches you with a new requirement: to create a multi-module app encompassing shopping, traveling, and ticket booking. The catch is that the shopping module must mirror the existing ABC app precisely. How do you tackle this challenge without duplicating your codebase? The solution lies in leveraging the existing project as a module while maintaining code efficiency and flexibility.

In essence, by intelligently repurposing the ABC app as a module, you not only meet your client’s requirement but also elevate the overall development process. This strategy not only accelerates the project timeline but also sets the foundation for a more adaptable, scalable, and maintainable multi-module app.

So, Now lets get the solution.

So, if you want to merge one Flutter project as a module into another Flutter project, follow these steps:

  1. Copy and paste your child project into your existing project.
  2. Go to your parent project's pubspec.yaml file and add the following:
dependencies:
flutter:
sdk: flutter
child_project_name:
path: ./child_project_path

3. After this, you’ll have access to your child project from the parent project.

If you also need to access the parent project from the child project, follow these steps:

  1. Go to your child project’s pubspec.yaml file and add the following:
dependencies:
flutter:
sdk: flutter
parent_project_name:
path: /parent_project_path

N.B: Remember, use full path for parent project otherwise your will not access your child project class.

2. After this, you’ll have access to your parent project from the child project.

Now you can access your child project from the parent project and the parent project from the child project.

Thanks for reading this article ❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.

--

--