Cretezy / flutter_linkify

Turns text URLs and emails into clickable inline links in text for Flutter
https://pub.dartlang.org/packages/flutter_linkify
MIT License
269 stars 101 forks source link

onOpen of SelectableLinkify is never called #31

Closed lukelyyeung closed 4 years ago

lukelyyeung commented 4 years ago

SelectableLinkify 's onOpen is never called. Maybe related to https://github.com/flutter/flutter/issues/43494

Platform: iOS 13.3

Reproducible code

import 'package:flutter/material.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import 'dart:async';

import 'package:url_launcher/url_launcher.dart';

void main() => runApp(new LinkifyExample());

class LinkifyExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'flutter_linkify example',
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter_linkify example'),
        ),
        body: Center(
          child: SelectableLinkify(
            onOpen: _onOpen,
            text: "https://github.com",
          ),
        ),
      ),
    );
  }

  Future<void> _onOpen(LinkableElement link) async {
    if (await canLaunch(link.url)) {
      await launch(link.url);
    } else {
      throw 'Could not launch $link';
    }
  }
}

flutter doctor result

[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.14.6 18G95, locale en-HK)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/setup/#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
      You may also want to add it to your PATH environment variable.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[!] Android Studio (not installed)
[✓] Connected device (2 available)

! Doctor found issues in 2 categories.
Cretezy commented 4 years ago

Yep this looks valid. I'll take a look at it later today!

nilsreichardt commented 4 years ago

Same issue.

Cretezy commented 4 years ago

Unfortunately, this seems to be a Flutter bug (as mentioned in the OP). I'll keep this ticket open until it is resolved upstream.

https://github.com/flutter/flutter/issues/43494

I've added a note in the README related to this.

da-revo commented 4 years ago

Same problem. Good Luck

Sameerkash commented 4 years ago

#28 43494

this seems to have the solution to the issue.

hkndzdr commented 4 years ago

#28 43494

this seems to have the solution to the issue.

I tested this example. It's not the right solution. It has a link feature in texts where there is no link feature. Multitext is everywhere clickable and has link feature. This is not what is desired.

dvird commented 4 years ago

@Cretezy ?

rajathk commented 4 years ago

@Cretezy Any update on this please?

Cretezy commented 4 years ago

This has been fixed in Flutter, see linked thread. Please run flutter upgrade. It might only be in master/dev so far, so hold on a bit longer!

rajathk commented 4 years ago

Thanks @Cretezy. Just verified the fix in dev channel version 1.18.0-10.0.pre.