How to ideally create multiple apps under same project in Flutter?

1,989

The best way I have figured out is using a package. Create a flutter package with common widgets, repositories, functions, etc in the packages. Then link the package to the apps. This can be done in two main ways.

1. Linking the package locally.

Here the local path to the package folder is added in pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  custom_package_name:
    path: path/to/package

This is very helpful if you are the only one working on the project. Because you don't have to publish it or push it to GitHub in order to reflect these changes in the apps that are linked to the packages

Using a relative path to the package is recommended, because if multiple teammates join the project, the absolute path may be differnt in differnt systems and leads to conflits in git. The new developers have to clone the package and the app project and arrange the package in the relative file path mentioned in the pubspec.yaml.

2. Lining the package in remote git repo.

Here the remote git repo link is added in pubspec.yaml.

dependencies:
  flutter:
    sdk: flutter
  common_package:
    git:
      url: https://github.com/path/to/common_package.git
      ref: master

ref is the branch name refernce. Here its the master branch. This is helpful when there is multiple developers, so that change made by everyone is updated to the remote repo and the package can be easily updated.

The developers dont need to clone the common_packages if thery are not contributing to it.

Share:
1,989
Abhijith K
Author by

Abhijith K

Working to make the dreams to reality.

Updated on December 21, 2022

Comments

  • Abhijith K
    Abhijith K over 1 year

    I am working on a project which requires an admin app and a customer app. Both these apps will have many things on common like the theme, images, fonts, widgets, packages, etc. So what is the ideal way to do this?

    If I create two separate projects, if there is a requirement to update the theme, I need to update it on two separate projects. How to handle the situation ideally?