Open In App

How to Import intl Library in Flutter?

Last Updated : 20 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Flutter supports using shared packages contributed by other developers to the Flutter and Dart ecosystems. This allows the developers to quickly build an app without having to develop everything from scratch. One such very helpful and Flutter Favourite package is the intl package published by the dart.dev.

To use the intl package as a library in our Flutter project we need to add the package as a dependency in our project which can be done in two ways as listed below.

Method 1: Adding intl package with a terminal command

Navigate to the terminal with its scope set to the root of the Flutter project and run the command given below,

flutter pub add intl

Method 2: Adding intl package manually via pubspec.yaml

The previous method automatically adds the package in pubspec.yaml, however you can do the same manually as well. You need to also add the package inside the pubspec.yaml file under the dependencies field as shown below:

dependencies:
    intl: <Package Version>

For example,
    intl: ^0.17.0

After writing the package details in the dependencies section in pubspec.yaml run the flutter pub get command in the terminal. When running flutter pub get for the first time after adding a package, Flutter saves the concrete package version found in the pubspec.lock lockfile. This ensures that you get the same version again if you, or another developer on your team, run flutter pub get.

After adding the package in pubspec.yaml whenever you are required to use the package add the below-shown import statement in the file.

import ‘package:intl/intl.dart’;

Now you can easily use the functions and widgets provided by the intl package in your Flutter project.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads