Using Packages

Flutter supports using shared packages contributed by other developers to the Flutter and Dart ecosystems. This allows quickly building an app without having to develop everything from scratch.

Packages : At a minimum, a Dart package is a directory containing a pubspec file. Additionally, a package can contain dependencies (listed in the pubspec), Dart libraries, apps, resources, tests, images, and examples. The pub.dev site lists many packages—developed by Google engineers and generous members of the Flutter and Dart community— that you can use in your app.

  1. Searching for packages
  2. Packages are published to pub.dev.
    The Flutter landing page on pub.dev displays top packages that are compatible with Flutter (those that declare dependencies generally compatible with Flutter), and supports searching among all published packages.

  3. Adding a package dependency to an app
  4. for example this package, shared_preferences

    You can follow the steps in the Installing part.

    1. Depend on it
    2. Open the pubspec.yaml file located inside the app folder, and add shared_preferences: under dependencies.

    3. Install it
    4. 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.

    5. Import it
    6. Add a corresponding import statement in the Dart code.

    7. Stop and restart the app, if necessary


For More Details : Flutter Docs