FLUTTER ECOSYSTEM

Cretezy/flutter_linkify

Flutterでテキスト内のURLとメールアドレスをクリック可能なインラインリンクに変換します

flutter_linkify のプロジェクト画像
Stars
266
Forks
107
最終プッシュ(UTC)
2024/03/26
プロジェクト状態
公開中
Cretezy GitHub avatar
GITHUB User

Cretezy ↗

Hi, I'm Cretezy, a software developer. I write open-source software, articles, and make YouTube videos.

@ServiceTitanCanada公式サイト ↗
言語C++CMakeDartSwiftHTMLCKotlinObjective-C

技術トピック

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 5 件
  • flutter{"sdk":"flutter"}
  • linkify^5.0.0
  • test開発用^1.0.0
  • flutter_test開発用{"sdk":"flutter"}
  • flutter_lints開発用^2.0.1

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

README を開く / 閉じる

flutter_linkify pub package

Turns text URLs and emails into clickable inline links in text for Flutter.

Required Dart >=2.17 (has null-safety support).

Pub - API Docs - GitHub

Install

Install by adding this package to your pubspec.yaml:

dependencies:
  flutter_linkify: ^6.0.0

It is highly recommend that you also add a dependency on url_launcher to open links in the browser/OS.

Usage

Basic:

import 'package:flutter_linkify/flutter_linkify.dart';

Linkify(
  onOpen: (link) => print("Clicked ${link.url}!"),
  text: "Made by https://cretezy.com",
);
Styling

Add a style to non-links (yellow) or links (red), and open in browser using url_launcher:

import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:url_launcher/url_launcher.dart';

Linkify(
  onOpen: (link) async {
    if (!await launchUrl(Uri.parse(link.url))) {
      throw Exception('Could not launch ${link.url}');
    }
  },
  text: "Made by https://cretezy.com",
  style: TextStyle(color: Colors.yellow),
  linkStyle: TextStyle(color: Colors.red),
);

All RichText options are available for use.

Linkify Options

By default, humanization (removal of http:// or https:// from the start of the URL) is enabled. You may disable it by passing options:

Linkify(
  text: "Made by https://cretezy.com",
  options: LinkifyOptions(humanize: false),
);
Selectable Text

Use the SelectableLinkify widget to create selectable text. All SelectableText options are available for use.

SelectableLinkify(
  text: "Made by https://cretezy.com\n\nMail: example@gmail.com",
);
Advance

In the onOpen callback, a LinkableElement is passed in. You can check if it is a UrlElement or EmailElement using is for custom handling.

You can enable parsing of only some link types using the linkifiers option. URL and email are enabled by default.

Full example can be found at example/lib/main.dart.

Example Screenshot