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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.