Reputation: 4616
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?
Upvotes: 20
Views: 10929
Reputation: 4616
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.
Upvotes: 15
Reputation: 2529
I think the appropriate solution is to create a package that contains similar codes so that you can use it in both projects, If it is only about icons, themes, etc., then you should use Flavor, Take a look at this article https://medium.com/@salvatoregiordanoo/flavoring-flutter-392aaa875f36
Upvotes: 1