Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 207
Kevan Avatar asked Jan 27 '26 08:01

Kevan


1 Answers

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

like image 73
Kevan Avatar answered Jan 28 '26 21:01

Kevan