Flutter essentials: get started with great libraries
Tags: flutter, dart, beginners
Published: 2020-12-09 16:14:23

Flutter is great! You can really do some amazing things in no time. It's just a matter of getting the hang of it. So, the first few times you'll probably need a bit of hand to achieve your goals. But don't worry, I'm sure you can do it! Your best source of knowledge here is obviously **pub.dev**, the great cauldron of Flutter libraries. In this article, I've tried to gather some of the greatest and most useful libraries that you'll surely find a need for.

Let's see what they are!

### **http**

This is not only useful, it's necessary if you want to do some HTTP requests in your app (even the [official Flutter website](https://flutter.dev/docs/cookbook/networking/fetch-data) suggest to use it!). It's really simple to use and comes with great options. Here's an example:


``` dart
var url = 'https://example.com/whatsit/create';
var response = await http.post(
       url, 
       body: {'name': 'doodle', 'color': 'blue'}
);

print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
print(await http.read('https://example.com/foobar.txt'));
```

You can find it [here](https://pub.dev/packages/http).

### **path_provider**

This is absolutely mandatory if you need to search and copy something on the file system. It's also a nice way to find commonly used locations on filesystem. This package also removes lots of boilerplate code that you should write on native platforms:


``` dart
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;

Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
```

Discover more about it [here](https://pub.dev/packages/path_provider)

### **shared_preferences**

What about NSUserDefaults and SharedPreferences? Great tools yeah, but on Flutter, you only need to use the **shared_preferences** package to access both as if by magic!

``` dart
SharedPreferences prefs = await SharedPreferences.getInstance();
```

Simple as that. Discover more [here](https://pub.dev/packages/shared_preferences).

### **cached_network_image**

Flutter has a nice way to show images from the web, but sometimes you wish for something more... efficient. This package not only shows images but also caches them. So, they're not downloaded every time you need to show them if you need to do it multiple times. For lists, this is absolutely awesome!

``` dart
CachedNetworkImage(
        imageUrl: "http://via.placeholder.com/350x150",
        placeholder: (context, url) => CircularProgressIndicator(),
        errorWidget: (context, url, error) => Icon(Icons.error),
     ),
```

Need a link to read about it? [Here it is](https://pub.dev/packages/cached_network_image)!

### **url_launcher**

This package lets you launch URLs on any platform easily. It uses the common HTTP schemes to identify if it's a website URL, a phone number, or other things.

``` dart
_launchURL() async {
  const url = 'https://flutter.dev';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}
```

As for the app-handled URLs, it's all up to the OS. Anyway, it will feel absolutely native.

You can find this package [here](https://pub.dev/packages/url_launcher).

### **permission_handler**

What's one of the most boring parts of programming? Asking for runtime permissions, right? Well, on Flutter you're pretty much obliged to use this package, but it'll make your life easier. Indeed, it provides you with some easy methods to obtain permissions and know whether certain permissions are given or not:

``` dart
var status = await Permission.camera.status;
if (status.isUndetermined) {
  // We didn't ask for permission yet.
}

// You can can also directly ask the permission about its status.
if (await Permission.location.isRestricted) {
  // The OS restricts access, for example because of parental controls.
}
```

Just remember also to add them to the Manifest file on Android...

You can find more about this package [here](https://pub.dev/packages/permission_handler).

### **provider**

> Provider is the recommended way to do State Management for apps of all sizes. 
> Chris Sells – Product Manager, Flutter. 
> June 19, 2019

The provider package is a State Management helper, which allows you to split the UI of your app from the business logic.

You can find more about this package [here ](https://flutter.dev/docs/development/data-and-backend/state-mgmt/simple)and also watch [this video](https://www.youtube.com/watch?v=HrBiNHEqSYU).


As you can see, there are lots of packages for Flutter! While some are a bit rough around the edges and others are way more advanced, if you need something, [pub.dev](https://pub.dev/) probably has it. Can't find what you need? Then, make a package yourself, dude, and get famous!! (but please, keep it updated...)!