Fluwx is a component based on wechat sharing
It can share pictures, applet, text, payment, and login
First, introduce FluwX in YAML
Fluwx: ^ Version numberCopy the code
Init needs to be called before formal sharing can be used
initFluwx() async { await fluwx.registerWxApi( appId: "wx83c491ea494cacb1", doOnAndroid: true, doOnIOS: false, ); var result = await fluwx.isWeChatInstalled(); print("is installed $result"); } clean -d -f The appId must be the same as the background setting of wechatCopy the code
Share pictures
The first thing to do is to introduce the page you are using:
import ‘package:fluwx/fluwx.dart’ as fluwx;
Dart 'as fluwx; dart' as fluwx; Fluwx. shareToWeChat(WeChatShareImageModelt(image: 'Assets ://images... png', transaction: 'test', scene: scene, description: "image" ) ); Fluwx. ShareToWeChat (WeChatShareImageModelt( WeChatImage.net work (" https://c-ssl.duitang.com/uploads/item/202004/15/20200415174537_ZzvUZ.thumb.1000_0.jpeg ") thumbnail:"assets://images/logo.png" ) ); 3, share data images fluwx. ShareToWeChat (fluwx. WeChatShareImageModel. FromUint8List (transaction: 'test,' imageData: PngBytes, / / uint8List scene: the format of the picture information fluwx. WeChatScene. TIMELINE, / / description: 'image')); 4, From file picture final tempDir = await getTemporaryDiretory(); String path = '${tempDir. Path} / image. JPG "; final file = await File(path).create(); file.writeAsBytesSync(pngBytes); / / will be fluwx. The binary files written to address shareToWeChat (fluwx. WeChatShareImageModel. FromFile (file, / / transaction flie file: 'test,' imageData: pngBytes, / / uint8List scene: the format of the picture information fluwx. WeChatScene. The TIMELINE, / / share the position description: 'image'));Copy the code
Second, share applets
Var model = fluwx. WeChatShareMiniProgramModel (webPageUrl: "-", miniProgramType: Fluwx. WXMiniProgramType. PREVIEW, the userName: "-", / / small program id the title: "-", path: "-", the description: "description", thumbnail: "Https://c-ssl.duitang.com/uploads/item/202004/15/20200415174537_ZzvUZ.thumb.1000_0.jpeg" / / thumbnails); fluwx.shareToWeChat(model); WXMiniProgramObject miniProgramObj = new WXMiniProgramObject(); WXMiniProgramObject(); miniProgramObj.webpageUrl = "http://www.qq.com"; / / low compatible version of the web page link miniProgramObj miniprogramType = WXMiniProgramObject. MINIPTOGRAM_TYPE_RELEASE; MiniProgramObj. UserName = "gh_d43f693ca31f"; // Miniprogramobj. path = "/pages/media"; // Applets page path; For small games, it is possible to pass only the Query part, for example: pass "? foo=bar" WXMediaMessage msg = new WXMediaMessage(miniProgramObj); MSG. Title = "applet message title "; // title msg.description = "applet message Desc"; ThumbData = thumbData (); Sendmessagetowx.req Req = new sendMessageTowx.req (); sendMessagetowx.req (); req.transaction = buildTransaction("miniProgram"); req.message = msg; req.scene = SendMessageToWX.Req.WXSceneSession; // Currently only session api.sendreq (req) is supported;Copy the code