Flutter packages

or How to share code between your apps

Danielle H
5 min readJan 27, 2023

Many of my apps communicate with a custom Bluetooth device. Also, many of my apps should have the same, or at least similar, branding. Therefore, many of my apps have common code.

We do NOT want duplicate code.

See? Other people say so too.

So we need a way to share code between apps.

There are two main options:

  1. Sharing a folder with Git Submodules.
  2. Sharing using a package with Flutter packages

Git Submodules

With Git Submodule, you basically insert a repository into another repository. So for the purpose of code sharing, this would look like this:

Git submodules (created using app.diagrams.net)

You have a separate git repository for your common code, but in your apps you pull from this repo into a subfolder. App1 sees the common code in the Util subfolder, and App2 also sees the common code in the Util subfolder (you can name the folder anything you wish, but this makes things clearer). The obvious pro of this method is that it’s very easy to change the common code as needed (the code of Util is right there).

--

--

Danielle H

I started programming in LabVIEW and Matlab, and quickly expanded to include Android, Swift, Flutter, Web(PHP, HTML, Javascript), Arduino and Processing.