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.


Haftanın Flutter Paketi: url_launcher

 

Herkese merhaba. Bu yazıyla Flutter projeleri geliştirirken kullanabileceğimiz, faydalı olacağını düşündüğüm “Haftanın Flutter Paketi” serisine başladığımı duyurmak isterim. İlk haftanın paketi, kendi geliştirdiğim projemde çok yakın zamanda kullandığım url_launcher.

url_launcher Nedir?

Uygulamanızdan kullanıcılarınızı harici bir URL’ye, bir web sayfasına, e-posta göndermeye ve hatta bir telefon numarasına yönlendirmek istiyorsanız, ihtiyacınız olan paket bu.

  • Örneğin bir butona basıldığında kullanıcının varsayılan tarayıcıya yönlendirilerek belirli bir URL’yi açabilmesini sağlamak.
  • Bir telefon numarasının telefonun standart arama uygulamasına kopyalanıp görüntülenmesini sağlamak.
  • Bir butona basıldığında alıcısını ve metnini oluşturacak şekilde email hazırlamak ve göndermek.

Kurulum

Terminale aşağıdaki satırı yazarak kurulum başlatabilirsiniz:

pubspec.yaml dosyasına aşağıdaki gibi eklenecektir:

Kullanım

1- Web Url’lerini Açma

Bir web URL’sini açmak için launch fonksiyonunu kullanabilirsiniz:

Not: canLaunch(url) verilen URL'nin açılıp açılamayacağını kontrol ederken launch(url) URL’yi tarayıcıda açar. launch(url) metodunu yazmadan url’yi kod içerisine direkt olarak da yazabilirsiniz ancak kullanıcının cihazı ile ilgili olası bir url açamama durumu olması halinde uygulamada sorun yaşanabilir. Bu sebeple metot içerisinde canLaunch(url) fonksiyonunu kullanmak özellikle önerilir.

2- Telefon Araması Yapma

Not: tel: prefix’i ile bir telefon numarası belirtilerek telefon araması yapılır.

3- SMS Gönderme

Not: sms: prefix’i kullanarak belirli bir numaraya SMS gönderme işlemi başlatılabilir.

4- E-posta Gönderme

Not: mailto: şeması kullanılarak bir e-posta gönderimi yapılır. querykısmında konu ve gövde içeriği belirlenebilir.

Uygulama İzinleri

iOS

ios/Runner/Info.plist dosyasına şu satırı ekleyerek internet erişimine izin vermelisiniz:

Android

android/app/src/main/AndroidManifest.xml dosyasında internet erişimi izni sağlamalısınız:

Umarım paketi detaylıca sunabilmişimdir, faydalı olmasını diliyorum. Önümüzdeki haftalarda başka paketlerde görüşmek üzere.

Kolay gelsin.

Selin.