There is any way to create custom link share via weChat from Flutter app?

139 Views Asked by At

this feature need to for flutter application to create customize share any kind of link,text or file without any wechat sdk implementation as like as others app sharing, so if anyone know this way to share customize link via wechat please answare this post to get support to yours, advance thank you for all

1

There are 1 best solutions below

0
On
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class ShareExample extends StatefulWidget {
  @override
  _ShareExampleState createState() => _ShareExampleState();
}

class _ShareExampleState extends State<ShareExample> {
  static final String _shareUrl = 'https://example.com/share';

  void _shareLink() async {
    if (await canLaunch('weixin://dl/moments')) {
      await launch('weixin://dl/moments?text=$_shareUrl');
    } else if (await canLaunch('weixin://dl/chat')) {
      await launch('weixin://dl/chat?text=$_shareUrl');
    } else {
      showDialog(
        context: context,
        builder: (context) => AlertDialog(
          title: Text('Share Link'),
          content: Text('Please install WeChat to share this link.'),
          actions: [
            TextButton(
              onPressed: () => Navigator.pop(context),
              child: Text('OK'),
            ),
          ],
        ),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Share Example'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: _shareLink,
          child: Text('Share Link'),
        ),
      ),
    );
  }
}
  1. The _shareLink function checks if the WeChat app is installed using the canLaunch function.
  2. If the WeChat app is installed, it opens the app and shares the link using one of the following URLs:
  • weixin://dl/moments: This URL opens the WeChat Moments app and shares the link to the user's Moments.
  • weixin://dl/chat: This URL opens the WeChat Chat app and shares the link with the user's last chat conversation.
  1. If the WeChat app is not installed, it displays an alert message asking the user to install the app.