1
votes

I am working on a Flutter project where I have a mobile application and a web application both are different e.g. one of them is a client application and the other one is the admin panel. But they have so many common files e.g. models and utils. But their dependencies are entirely different e.g. firebase for flutter(iOS and Android) and firebase for Dart. I want to share common files between 2 projects but I want to keep their dependencies separate as I don't want to build useless dependencies with another project. How can I do this? I have good experience with Android Flavouring but I am unable to accomplish this here. can I have separate dependencies for both? I googled and found much data regarding flutter flavors but I couldn't find my answer.

1
any update on this? - Shashwat Aditya

1 Answers

0
votes

You can try to create a flutter package and share the package between the projects see https://flutter.dev/docs/development/packages-and-plugins/developing-packages

create the package (e.g. my_pkg) in folder next to your app folder

move the files you want to share to the my_pkg project

then in your puspec.yaml you can do this

dependencies:
  flutter:
    sdk: flutter
  my_pkg:
    path: ../my_pkg/

the only other change in your code would be the import statements of the class that you moved to my_pkg

Hope it answer your question.