Kevan
Kevan

Reputation: 373

How do you share code between 2 Flutter projects?

With Flutter now supporting web and mobile app development, what's the best practice to avoid rewriting code all the time? Say you have a few classes / functions living in your mobile app project that'd you'd like to reuse for your web project, is importing these files the way to go? If so, can you do that across multiple projects?

Upvotes: 15

Views: 4967

Answers (1)

Kevan
Kevan

Reputation: 373

Here is the approach I found: using packages.

You can create a package with the following terminal command:

flutter create --template=package myPackageName

then simply create whatever class, function, etc. you want to share across your projects in the package and import them in your other Flutter projects.

Here is an example: https://youtu.be/MJO695IE-EA

Upvotes: 19

Related Questions