Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/festelo/native_linkify

Flutter plugin which helps you to find links in String using NSDataDetector and Linkify
https://github.com/festelo/native_linkify

dart flutter linkify

Last synced: 3 months ago
JSON representation

Flutter plugin which helps you to find links in String using NSDataDetector and Linkify

Awesome Lists containing this project

README

        


Build & Test
codecov
License: Apache 2.0

# Flutter's Native Linkify
![Example screenshot](resources/screenshot.png)

`native_linkify` is a Flutter plugin. Use it to find links in plain-text.

The plugin uses [NSDataDetector](https://developer.apple.com/documentation/foundation/nsdatadetector) for iOS and macOS; [Linkify](https://developer.android.com/reference/android/text/util/Linkify) for Android. This means the plugin finds links in the same way most native apps do, giving much more accurate results than existing pure dart packages.

This plugin doesn't have any widgets to show inline links out of the box, but it has everything you need to create them in a way you like.

Here's example which shows how to implement widget that's turns text URLs, E-Mails and phones into clickable links:
```dart

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

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

void main() async {
WidgetsFlutterBinding.ensureInitialized();
final entries = await NativeLinkify.linkify(
'text link.com [email protected] and +79990000000');
// Note that this method is asynchronous because the plugin works with native
// functions via MethodChannel and MethodChannel works only in asynchronous way
// in real app it's better to linkify text at the place where you load it from
// your data source
runApp(
MyApp(
entries: entries,
),
);
}

class MyApp extends StatelessWidget {
const MyApp({Key? key, required this.entries}) : super(key: key);

final List entries;

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Text.rich(
TextSpan(
children: [
for (final l in entries)
if (l is LinkifyText)
// Regular text, text without links
TextSpan(
text: l.text,
)
else if (l is LinkifyUrl)
// Link
TextSpan(
text: l.text,
style: const TextStyle(color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () => launch(l.url),
)
],
),
),
),
),
);
}
}
```