appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
187 stars 214 forks source link

[ BUG ] : Share to Instagram Direct works on Android and iOS, but Stories do not on iOS #261

Closed lisovyk closed 5 months ago

lisovyk commented 5 months ago

Plugin name Appinio social share

Describe the bug I encountered a bug where my test users on ios can't share to instagram stories while the share-to-direct is present. Facebook Stories work as intended on both platforms.

To Reproduce Steps to reproduce the behavior: I don't have an iOS physical device and it's not possible to install apps on simulator - thanks apple - so no way to create a reproducable example for me.

Expected behavior Instagram Story share works both on Android and iOS. I suspect facebook Stories might be broken too but no way to

Screenshots android and ios screenshots, same app version:

Screenshot 2024-03-26 at 16 44 03

2024-03-26 16 44 07

Smartphone (please complete the following information):

Additional context Here are parts of the code I am using, if it will be of any help. Thanks.

FutureBuilder(
                    future: AppinioSocialShare().getInstalledApps(),
                    builder: (context, snapshot) {
                      if (snapshot.connectionState == ConnectionState.waiting) {
                        return const Center(child: CircularProgressIndicator());
                      }
                      if (snapshot.hasError) {
                        return Center(
                          child: Text('Помилка: ${snapshot.error}'),
                        );
                      }

                      List<SharePlatform> sharePlatformsFiltered = [];
                      if (snapshot.data != null && snapshot.data!.isNotEmpty) {
                        print(snapshot.data!.entries);
                        // print all entries values
                        print(snapshot.data!.entries.map((e) => e.value).toList());
                        final installedShareApps = snapshot.data!.entries.where((e) => e.value).map((e) => e.key).toList();
                        sharePlatformsFiltered =
                            SharePlatform.defaults.where((e) => installedShareApps.contains(e.platform_name)).toList();
                      }

                      return _buildShareOptionsGrid(theme, sharePlatformsFiltered, context);
                    },
SingleChildScrollView _buildShareOptionsGrid(ThemeData theme, List<SharePlatform> sharePlatformsFiltered, BuildContext context) {
    return SingleChildScrollView(
      child: GridView.count(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        crossAxisCount: 4,
        childAspectRatio: 1,
        children: [
          _buildCell(
            theme,
            Remix.links_line,
            'Скопіювати посилання',
            onTap: () {
              Clipboard.setData(ClipboardData(text: url));
              if (Platform.isIOS) {
                snackbarKey.currentState?.showSnackBar(const SnackBar(content: Text('Посилання скопійовано')));
              }
            },
          ),
          ...sharePlatformsFiltered
              .map(
                (SharePlatform e) => _buildCell(
                  theme,
                  e.icon,
                  e.name,
                  onTap: () async {
                    if (e.platform_name == SharePlatform.telegram.platform_name) {
                      File file = await generatePicture(context, theme, background: true);
                      AppinioSocialShare().shareToTelegram('Посилання: $url', filePaths: [file.path]);
                      // AppinioSocialShare().shareToTelegram(url);
                      // https://core.telegram.org/widgets/share
                    } else if (e.platform_name == SharePlatform.instagram_story.platform_name) {
                      File file = await generatePicture(context, theme);
                      await AppinioSocialShare().shareToInstagramStory(FACEBOOK_APP_ID,
                          stickerImage: file.path,
                          backgroundBottomColor: '#${backgroundBottomColor.value.toRadixString(16)}',
                          backgroundTopColor: '#${backgroundTopColor.value.toRadixString(16)}',
                          attributionURL: url);
                    } else if (e.platform_name == SharePlatform.instagram_direct.platform_name) {
                      await AppinioSocialShare().shareToInstagramDirect(url);
                    } else if (e.platform_name == SharePlatform.facebook_messenger.platform_name) {
                      await AppinioSocialShare().shareToMessenger(url);
                    } else if (e.platform_name == SharePlatform.facebook_story.platform_name) {
                      File file = await generatePicture(context, theme);
                      await AppinioSocialShare().shareToFacebookStory(
                        FACEBOOK_APP_ID,
                        backgroundBottomColor: '#${backgroundBottomColor.value.toRadixString(16)}',
                        backgroundTopColor: '#${backgroundTopColor.value.toRadixString(16)}',
                        stickerImage: file.path,
                        attributionURL: url,
                      );
                    } else if (e.platform_name == SharePlatform.twitter.platform_name) {
                      File file = await generatePicture(context, theme, background: true);
                      await AppinioSocialShare().shareToTwitter(
                        url,
                        filePaths: [file.path],
                      );
                    } else if (e.platform_name == SharePlatform.whatsapp.platform_name) {
                      File file = await generatePicture(context, theme, background: true);
                      await AppinioSocialShare().shareToWhatsapp(
                        url,
                        filePaths: [file.path],
                      );
                    }
                  },
                ),
              )
              .toList(),
          _buildCell(theme, Remix.more_line, 'Більше', onTap: () => Share.share(url)),
        ],
      ),
class SharePlatform {
  const SharePlatform({
    required this.name,
    required this.platform_name,
    required this.icon,
  });
  final String name;
  final String platform_name;
  final IconData icon;

  static SharePlatform get telegram => const SharePlatform(
        name: 'Телеграм',
        platform_name: 'telegram',
        icon: Remix.telegram_line,
      );

  // facebook messenger
  static SharePlatform get facebook_messenger => const SharePlatform(
        name: 'Messenger',
        platform_name: 'messenger',
        icon: Remix.messenger_line,
      );
  static SharePlatform get facebook_story => const SharePlatform(
        name: 'Історії',
        platform_name: 'facebook_stories',
        icon: Remix.messenger_line,
      );
  // whatsapp
  static SharePlatform get whatsapp => const SharePlatform(
        name: 'WhatsApp',
        platform_name: 'whatsapp',
        icon: Remix.whatsapp_line,
      );

  static SharePlatform get instagram_story => const SharePlatform(
        name: 'Історії',
        platform_name: 'instagram_stories',
        icon: Remix.instagram_line,
      );

  static SharePlatform get instagram_direct => const SharePlatform(
        name: 'Повідомлення',
        platform_name: 'instagram',
        icon: Remix.instagram_line,
      );

  static SharePlatform get twitter => const SharePlatform(
        name: 'Twitter',
        platform_name: 'twitter',
        icon: Remix.twitter_line,
      );

  static List<SharePlatform> get defaults => <SharePlatform>[
        telegram,
        instagram_story,
        instagram_direct,
        facebook_messenger,
        facebook_story,
        twitter,
        whatsapp,
      ];
}
lisovyk commented 5 months ago

oopsie, my internet connection lagged...