Home > front end >  how can i fix this issue 'canLaunch' is deprecated and shouldn't be used. Use canLaun
how can i fix this issue 'canLaunch' is deprecated and shouldn't be used. Use canLaun

Time:10-22

    Container(
                  child: Row(
                    children: [
                      Icon(
                        Icons.facebook,
                        color: Colors.blue,
                      ),
                      RichText(
                          text: TextSpan(
                            children: [
                              TextSpan(
                                style: defaultText,
                                text: " Visit Facebook Page",
                                  recognizer: TapGestureRecognizer()..onTap = () async {
                                    var url = "https://www.facebook.com/minorijapaneserestaurant";
                                    if(!await canLaunch(url,)) {
                                      await launch(url);
                                    } else {
                                      throw "Cannot load Url $url";
                                    }
                                  }
                              )
                            ]
                          ),
                      )],
                  ),
                ),

CodePudding user response:

As canLaunch and launch methods are deprecated in url_launcher. Now you can use canLaunchUrl instead of canLaunch and launchUrl instead of launch i.e.

var url = "https://www.facebook.com/minorijapaneserestaurant"; 
if(await canLaunchUrl(Uri.parse(url))) { 
  await launchUrl(Uri.parse(url)); 
} else { 
  throw "Cannot load Url $url";
}

CodePudding user response:

Welcome to SO.

Do as the message says, replace canLaunch(url) with canLaunchUrl(url).

  • Related