Flutter Dependencies and Packages
Core Packages
Flutter comes with many packages by default. These are called Core Packages and you don’t need to declare any kind of external dependency to use them.Non-Core Packages
You could call these ‘External Packages’. These are packages that are not setup by default. You need to declare these dependencies and pull them into your project to use them.Declare Dependency in Project
Open the pubspec.yaml file in the root of your project and add a dependency. For example, the code below declares dependencies to the flutter sdk, cupertino icons and scoped_model. Note how somedependencies specify the version, some don’t:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
scoped_model: ^1.0.1
Import Packages
Once your pubspec.yaml file is setup, you need to install the packages by pulling them from https://pub.dartlang.org/ . Normally your editor will assist you with this.Android Studio
Click ‘Packages Get’ in the action ribbon at the top of pubspec.yamlVisual Studio Code
Click ‘Get Packages’ located in right side of the action ribbon at the top of pubspec.yamlCommand-Line
Run the command ‘flutter packages get’.Import & Use Package Code
You import the package code in the usual manner using the ‘import’ statement at the top of your code. For example, the code imports the flutter material package and the scoped model package.import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';
Restart Your App
You will probably need to restart your app if it is running.
That’s it!