flutter_autolink_text 1.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

flutter_autolink_text #

pub package

About #

Text widget, that turns URLs, email and phone numbers into clickable inline links in text for flutter

Install #

Install by adding this package to your pubspec.yaml:

dependencies:
  flutter_autolink_text: ^1.0.0+1

Usage #

Basic: #

import 'package:flutter_autolink_text/flutter_autolink_text.dart';

AutolinkText(
	text: 'Your text with link www.example.com',
	textStyle: TextStyle(color: Colors.black),
	linkStyle: TextStyle(color: Colors.blue),
	onWebLinkTap: (link) => print('Clicked: ${link}')
);

To add autolink to emails and phone numbers:

import 'package:flutter_autolink_text/flutter_autolink_text.dart';

AutolinkText(
	text: ...,
	textStyle: TextStyle(color: Colors.black),
	linkStyle: TextStyle(color: Colors.blue),
	onWebLinkTap: (link) => print('Clicked: ${link}'),
	onEmailTap: (link) => print('Clicked: ${link}'),
	onPhoneTap: (link) => print('Clicked: ${link}')
);

If you're using url_launcher to open your links in browser, you can add mailto: for emails and tel: for phone numbers to open them in other apps

Humanizing: #

Remove http:// or https:// from the start of the URL using humanize:

import 'package:flutter_autolink_text/flutter_autolink_text.dart';

AutolinkText(
	text: 'Link is https://example.com',
	humanize: true,
	...
);

[1.0.0]

Initial version

[1.0.0+1]

Code refactoring

example/lib/main.dart

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'flutter_autolink_text example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'flutter_autolink_text example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  GlobalKey<ScaffoldState> scaffold = new GlobalKey();

  void showSnack(String link) {
    scaffold.currentState.showSnackBar(SnackBar(content: Text('Clicked: ${link}')));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: scaffold,
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: AutolinkText(
            text: 'Your text with link www.example.com',
            textStyle: TextStyle(color: Colors.black),
            linkStyle: TextStyle(color: Colors.blue),
            onWebLinkTap: (link) => showSnack(link)
        ),
      ),// This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_autolink_text: ^1.0.0+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_autolink_text/flutter_autolink_text.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
9
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Health suggestions

Fix lib/flutter_autolink_text.dart. (-0.50 points)

Analysis of lib/flutter_autolink_text.dart reported 1 hint:

line 12 col 7: This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: AutolinkText.humanize

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test