skip to Main Content

In Android we have https://developer.android.com/reference/android/text/util/Linkify

and https://developer.android.com/reference/android/widget/TextView#attr_android:autoLink

so for example if you SMS someone an address properly formatted with city state it lets you pull up google maps when you tap on it.

How do you achieve this in flutter? The packages I find either support only url, or emamil or phone number maybe but not address.

https://pub.dev/packages/selectable_autolink_text etc

2

Answers


  1. Assume you have an address:

    var address = '1 Maritime Square, Singapore 099253';
    

    You build a Google Map URL to launch:

    var googleMapslocationUrl =
            "https://www.google.com/maps/search/?api=1&query=$address"; 
    

    Build an Inkwell widget for user:

    InkWell(
                  onTap: () => launchUrl(Uri.parse(googleMapslocationUrl)),
                  child: Text(address,
                      style: const TextStyle(
                        color: Colors.blue,
                        decoration: TextDecoration.underline,
                      )),
                ),
    

    The launchUrl function is from the url_launcher package: https://pub.dev/packages/url_launcher
    Hope this help.

    Login or Signup to reply.
  2. import 'package:flutter/gestures.dart';
    ...
    
    new RichText(
          text: new TextSpan(text: 'Non touchable. ', children: [
            new TextSpan(
              text: 'Tap here.',
              recognizer: new TapGestureRecognizer()..onTap = () => print('Tap Here onTap'),
            )
          ]),
        );
    

    You can use RichText for Linkredirects
    for like Terms&condition etc.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search