Package Usage Example

Now that you know how to install packages, you’ll get to see packages in action.

Getting Started

We are going to build a simple app that displays the phone’s battery and connectivity state using the battery[28] and connectivity[29] packages from Pub:


To use those packages, we’ll start by adding the packages to our app’s dependencies, and you can do that by adding the following to the dependencies in pubspec.yaml:

 connectivity: ​^0.3.1
 battery: ​^0.2.2

And import the packages in our code by adding to the top of the main Dart file the following:

Get Programming Flutter now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.