Link Widget — Flutter 2.0

Farrukh Sajjad
2 min readApr 6, 2021

Flutter announced a new widget with the latest version of “url_launcher,” called “Link” widget. What it does is minimizes the old way of launching URLs and making it more easy to use and the biggest upgrade is that it now show’s the targeted URL at the bottom left of the browser screen 😉.

link widget flutter
Link Widget — Flutter
  1. You have to import url_launcher and upgrade your flutter SDK to 2.0.
url_launcher: ^6.0.3

2. Link is a widget like everything else in flutter (duhhh).

What does Link Widget do?

Creates a widget that renders a real link on the web, and uses WebViews in native platforms to open links.

Link(target: LinkTarget.defaultTarget,uri: Uri.parse(“http://farrukhsajjad.github.io/"),builder: (context, followLink) {return ElevatedButton(onPressed: launchSomething,child: Text(‘Launch’),);},),

Link widget accepts 2 parameters.

  1. uri: which will consists of targeted URL.
  2. a builder function to create a UI element for the user.
  3. optional parameters like, target: allow us to open the link in the new browser tab or in the same app rather than opening in the browser.

target: LinkTarget.blank,

is going to open the link in the new tab.

target: LinkTarget.self,

is going to open the link natively in the app.

COMPLETE CODE:

import 'package:flutter/material.dart';import 'package:url_launcher/link.dart';class Home extends StatelessWidget {launchSomething() {print('object');}@overrideWidget build(BuildContext context) {return Scaffold(body: SafeArea(child: Center(child: Link(target: LinkTarget.self,uri: Uri.parse("http://farrukhsajjad.github.io/"),builder: (context, followLink) {return ElevatedButton(onPressed: launchSomething,child: Text('Launch'),);},),),));}}
link widget flutter
Link Widget Flutter

👏

Sign up to discover human stories that deepen your understanding of the world.

Farrukh Sajjad
Farrukh Sajjad

Written by Farrukh Sajjad

Noob Game Dev | Back to posting weekly

No responses yet

Write a response