Using packages – Adding a package dependency to an app

To add the package css_colors to an app:

Depend on it

Open the pubspec.yaml file located inside the app folder, and add css_colors: ^1.0.0 under dependencies.

Install it

From the terminal: Run flutter pub get.

OR

From VS Code: Click Get Packages located in right side of the action ribbon at the top of pubspec.yaml indicated by the Download icon.

From Android Studio/IntelliJ: Click Pub get in the action ribbon at the top of pubspec.yaml.

Import it

Add a corresponding import statement in the Dart code.

Stop and restart the app, if necessary

If the package brings platform-specific code (Kotlin/Java for Android, Swift/Objective-C for iOS), that code must be built into your app. Hot reload and hot restart only update the Dart code, so a full restart of the app might be required to avoid errors like MissingPluginException when using the package.

Leave a comment

Your email address will not be published. Required fields are marked *