The Flutter Package of the Week: url_launcher

 


Hello everyone. With this article, I would like to announce that I have started the ‘Flutter Package of the Week’ series, which I think will be useful when developing Flutter projects. The first week’s package is url_launcher, which I recently used in my own project.

What is url_launcher ?

If you want to redirect your users from your app to an external URL, a web page, an email, or even a phone number, this is the package you need.

  • For example, when a button is pressed, the user is redirected to the default browser so that they can open a specific URL.
  • Enabling a phone number to be copied into the phone’s standard dialling application and displayed.
  • Prepare and send an email to generate the recipient and text when a button is pressed.

Installation

You can start the installation by typing the following line in the terminal:

It will be added to the pubspec.yaml file as follows:

Usage

1- Opening Web Urls

You can use the launch function to open a web URL:

Note: While canLaunch(url) checks whether the given URL can be opened, launch(url)opens the URL in the browser. You can also write the url directly in the code without writing the launch(url) method, but there may be problems in the application in case of a possible inability to open the url related to the user’s device. For this reason, it is especially recommended to use the canLaunch(url)function in the method.

2- Making a Phone Call

Note: A telephone call is made by specifying a telephone number with the prefix tel: .

3- Sending SMS

Note: SMS to a specific number can be initiated using the sms:prefix.

4- Sending E-mail

Note: An e-mail is sent using the mailto:scheme. The subject and body content can be specified in the query section.

Application Permissions

iOS

You must allow internet access by adding the following line to the ios/Runner/Info.plist file:

Android

You must provide internet access permission in android/app/src/main/AndroidManifest.xmlfile:

I hope you found this article useful! If you appreciate the information provided, you have the option to support me by Buying Me A Coffee! Your gesture would be greatly appreciated!


I hope I have been able to present the package in detail, I wish it to be useful. See you in the coming weeks with other packages.

Have a good day.

Selin.


Hiç yorum yok: