Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
  • Flutter Apps
Menu
Flutter URL Launcher

Flutter URL Launcher

Posted on November 13, 2024 by Toma Velev

I’m bringing light to a Flutter Plugin – URL Launcher, because the core idea is a lot more than URL and a lot more than Launcher – bigger than Flutter.

The url_launcher package in Flutter is a plugin that allows you to open URLs from your Flutter app, using the device’s default browser or other installed apps (e.g., email client). Let’s explore how it fits into the evolution of the launcher concept:

Evolution of the Launcher Concept

  1. Web 2.0 – In-app Handling: In this era, web applications were primarily accessed through a browser. When you clicked on a link within an app, the default behavior was to open the URL in a new tab or window within the same application.
  2. Web 3.0 – 3rd party integration and the Decentralized World: With the rise of decentralized technologies like blockchain, IoT, and WebAssembly, we’re entering a new era where applications can interact with each other in more sophisticated ways.

Using url_launcher in Flutter

To use url_launcher, add it to your pubspec.yaml file:

dependencies:
  url_launcher: ^6.1.4

Then, import the package and call the launch function to open a URL:

import 'package:url_launcher/url_launcher.dart';

void main() {
  _launchURL();
}

Future<void> _launchURL() async {
  final Uri url = Uri.parse('https://www.example.com');
  if (await canLaunchUrl(url)) {
    await launchUrl(url);
  } else {
    throw 'Could not launch $url';
  }
}

In this example, we use the canLaunchUrl function to check if the device’s default browser or other installed apps can handle the URL. If it can be launched, we call the launchUrl function to open the URL.

Intent URI Format

An Intent URI has the following format:

intent://[action]=[param1]#[param2]?[query]=value

Here’s a breakdown:

  • intent: specifies that this is an intent URI
  • [action]: the action to be performed (e.g., view, edit)
  • [param1] and [param2]: optional parameters for the action
  • ?: separates the query from the rest of the URI
  • [query]=value: a query parameter with its value

Launching Other Apps

To launch other apps using an Intent URI, you can use the launch function from the url_launcher package:

import 'package:url_launcher/url_launcher.dart';

void main() {
  _launchIntentUri();
}

Future<void> _launchIntentUri() async {
  final uri = Uri.parse('intent://view#param1=value1&param2=value2?query=value');
  if (await canLaunch(uri)) {
    await launch(uri);
  } else {
    throw 'Could not launch $uri';
  }
}

In this example, the launch function will attempt to open an app that handles Intent URIs with the specified action (view) and parameters. If an app is found that can handle the URI, it will be launched.

Supported Actions

The following actions are supported:

  • view: opens a document or other content for viewing
  • edit: allows editing of a document or other content
  • share: shares content with others
  • send: sends content via email or messaging

You can use these actions by replacing [action] in the Intent URI format above.

Example Use Cases

  1. Opening an email client:
final uri = Uri.parse('mailto:user@example.com?subject=Hello&body=Hi');
launch(uri);
  1. Opening a PDF viewer:
final uri = Uri.parse('intent://view#file:///path/to/document.pdf');
launch(uri);
  1. Sharing content on social media:
final uri = Uri.parse('intent://share#text=Hello World&url=https://example.com');
launch(uri);

Remember to replace the placeholder values with your actual data.

By using Intent URIs, you can leverage the capabilities of other apps installed on a user’s device, making your Flutter app more integrated and feature-rich.

Flutter Options for Opening Internet Addresses

Flutter allows you to open Internet URLs within your app without exiting the app using several approaches:

  1. WebView: You can use a WebView widget from the flutter_webview_pro package or the built-in flutter_html package to display web content within your app.
  2. Custom Tab – you can use the https://pub.dev/packages/flutter_custom_tabs package to open URLs in Chrome Custom Tabs without exiting your app.
  3. In-app browsers: You can also use third-party libraries like in_app_browser or flutter_inappwebview to display web content within your app.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • What are ways to Optimize the backend endpoints in Spring Boot
  • Flutter image flickers
  • Could a Flutter App save a Flag even after uninstall
  • Could iOS flutter app logs be viewed while running in release mode – started after previous closed state
  • 6 Addictive Mobile Game Ideas Inspired by Flappy Bird’s Simplicity

Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (206)
  • Graphical User Interface (13)
  • Marketing (114)
  • Software Development (270)
  • Spring (43)
  • StartUp (21)
  • Uncategorized (4)
  • Uncategorized (15)
  • Vaadin (14)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (83)
    • Flutter Apps (23)
    • GPT (4)
    • Java (38)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (35)
    • Utils (15)
    • Vaadin 24+ (27)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • What are ways to Optimize the backend endpoints in Spring Boot
  • Flutter image flickers
  • Could a Flutter App save a Flag even after uninstall
  • Could iOS flutter app logs be viewed while running in release mode – started after previous closed state
  • 6 Addictive Mobile Game Ideas Inspired by Flappy Bird’s Simplicity

Post Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (206)
  • Graphical User Interface (13)
  • Marketing (114)
  • Software Development (270)
  • Spring (43)
  • StartUp (21)
  • Uncategorized (4)
  • Uncategorized (15)
  • Vaadin (14)