![](/img/trans.png)
[英]Flutter url_launcher open Facebook link inside app(Facebook) installed but in IOS it just open facebook and not the link
[英]Open Facebook app with url_launcher package in Flutter
我試圖在 Flutter 的公司頁面上打開 Facebook 應用程序,但它一直在 web 瀏覽器中打開它。
它只是一個簡單的小部件,可以從列表中輸出一行社交媒體圖標:
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class SocialMediaLinks extends StatelessWidget {
SocialMediaLinks({Key? key}) : super(key: key);
final List<Map<dynamic, dynamic>> icons = [
{
'name': 'twitter',
'launchUrl': 'twitter://PAGENAME',
'backupUrl': 'https://twitter.com/PAGENAME',
},
{
'name': 'facebook',
'launchUrl': 'fb://page/PAGEID',
'backupUrl': 'https://www.facebook.com/PAGENAME',
},
{
'name': 'instagram',
'launchUrl': 'instagram://PAGENAME',
'backupUrl': 'https://www.instagram.com/PAGENAME',
}
];
@override
Widget build(BuildContext context) {
return Row(
children: [
for (Map i in icons)
IconButton(
onPressed: () async {
await canLaunch(i['launchUrl'])
? launch(
i['launchUrl'],
forceSafariVC: false,
forceWebView: false,
)
: launch(
i['backupUrl'],
forceSafariVC: false,
forceWebView: false,
);
},
splashRadius: 30.0,
iconSize: 38.0,
icon: Image.asset(
"assets/images/icons/${i['name']}.png",
color: Colors.white,
),
),
],
);
}
}
Twitter 和 Instagram 在他們的應用程序中工作和打開,但 Facebook 仍然只能在 web 瀏覽器中打開。 我在 stackoverflow 上嘗試了很多解決方案,但無濟於事。 我錯過了什么嗎?
謝謝。
我觀察到在 Facebook 應用程序中配置的支持的 URL 存在限制。 In Android at least, while the Facebook app has support for facebook.com
, I noticed that the Facebook app opens when it's a link to a specific post ie https://www.facebook.com/$profileId/posts/$postId
但是,Facebook 應用程序似乎無法處理指向個人資料或頁面的直接鏈接,即https://www.facebook.com/$profileId
如果您鏈接到 Facebook 中的個人資料/頁面,您可以在個人資料/頁面中固定帖子並共享 Facebook 帖子的鏈接作為解決方法。 這應該會成功打開設備上安裝的 Facebook 應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.