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
In Flutter - how to have a text with a Hyperlink

In Flutter – how to have a text with a Hyperlink

Posted on April 27, 2025May 10, 2025 by Toma Velev

In Flutter, if you want a text with a clickable hyperlink inside it, you typically use a RichText widget with a TextSpan, and you add a gesture recognizer to detect taps.

Here’s a simple example:

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class HyperlinkTextExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Hyperlink in Text')),
      body: Center(
        child: RichText(
          text: TextSpan(
            text: 'Click ',
            style: TextStyle(color: Colors.black, fontSize: 18),
            children: [
              TextSpan(
                text: 'here',
                style: TextStyle(color: Colors.blue, decoration: TextDecoration.underline),
                recognizer: TapGestureRecognizer()
                  ..onTap = () {
                    // Handle the tap - e.g., open a URL
                    print('Hyperlink tapped!');
                  },
              ),
              TextSpan(
                text: ' to learn more.',
              ),
            ],
          ),
        ),
      ),
    );
  }
}

If you want to open a real URL, you can use the url_launcher– package.

Quick example for launching a URL:

import 'package:url_launcher/url_launcher.dart';

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

RichText is a very powerful widget that allows you to display text with multiple styles in a single block. Unlike a simple Text widget, RichText lets you customize parts of the text differently (like bolding one word, coloring another, etc.).

Here are the main features of RichText:

1. Multiple Text Styles
You can apply different fonts, colors, sizes, weights, decorations (underline, strikethrough, etc.) to different parts of the text.

2. Inline Formatting
By using a tree of TextSpans inside the RichText, you can format each span independently.

3. Fine Control over Text Layout
It gives you more control over things like text alignment, overflow, max lines, scaling, and soft wrapping.

4. Accessibility Support
Proper semantics are created for accessibility readers (like TalkBack or VoiceOver).

5. Performance Optimized
Flutter optimizes how RichText is rendered internally, so even complex styled texts are rendered efficiently.

7. Directionality
Supports left-to-right (LTR) and right-to-left (RTL) text based on the textDirection.


Basic Example:

RichText(
  text: TextSpan(
    text: 'Hello ',
    style: TextStyle(color: Colors.black, fontSize: 20),
    children: <TextSpan>[
      TextSpan(
          text: 'bold',
          style: TextStyle(fontWeight: FontWeight.bold)),
      TextSpan(
          text: ' and ',
          style: TextStyle(fontStyle: FontStyle.italic)),
      TextSpan(
          text: 'colorful!',
          style: TextStyle(color: Colors.red)),
    ],
  ),
)

RichText gives you the possibility to render HTML like content, but execute something from within the app. If you need to render more tags and content – check out some of the Flutter HTML Solutions.

  • Example of GridView Builder in Flutter
  • How to Visualize Listview inside Listview in Flutter
  • What other usages you know about public private cryptography
  • Get a Flutter App to Production
  • Firebase Dynamic Links Deprecation – migrating out to Java

Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (201)
  • Graphical User Interface (13)
  • Marketing (113)
  • Software Development (268)
  • Spring (41)
  • StartUp (21)
  • Uncategorized (15)
  • Uncategorized (4)
  • 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

  • Example of GridView Builder in Flutter
  • How to Visualize Listview inside Listview in Flutter
  • What other usages you know about public private cryptography
  • Get a Flutter App to Production
  • Firebase Dynamic Links Deprecation – migrating out to Java

Post Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (201)
  • Graphical User Interface (13)
  • Marketing (113)
  • Software Development (268)
  • Spring (41)
  • StartUp (21)
  • Uncategorized (15)
  • Uncategorized (4)
  • Vaadin (14)