0

I am trying to open the Facebook app on a company page in Flutter but it keeps opening it in the web browser instead.

It's just a simple widget that outputs a row of social media icons from a list:

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 and Instagram work and open in their apps but Facebook still only opens in the web browser. I've tried tonnes of solutions on stackoverflow but to no avail. Am I missing something?

Thanks.

danny471
  • 335
  • 7
  • 17
  • 1
    see this [one here](https://stackoverflow.com/a/60503740/13833108), it could help you – devmuaz Jan 03 '22 at 08:50
  • Do you solve this issue? I also facing same issue. Most of the plugin does not working in iOS. So I decide to use url_launcher – Alex Aung Feb 13 '22 at 17:04
  • I ended up using the one AbdulMuaz Aqeel posted above – danny471 Feb 16 '22 at 01:02
  • Does this answer your question? [Flutter open facebook link in facebook app android & ios](https://stackoverflow.com/questions/55838430/flutter-open-facebook-link-in-facebook-app-android-ios) – Leviathan May 27 '22 at 09:57

1 Answers1

1

I've observed a limitation with the supported URLs configured in the Facebook app. 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 i.e. https://www.facebook.com/$profileId/posts/$postId

Facebook app supported links

However, the Facebook app seems to be unable to handle direct links to the profile or page i.e. https://www.facebook.com/$profileId

If you're linking to a profile/page in Facebook, you can pin a post in the profile/page and share the link of the Facebook post as a workaround. This should successfully open the Facebook app installed on the device.

Omatt
  • 8,564
  • 2
  • 42
  • 144