flutter_wechat 0.1.5

flutter_wechat #

A flutter plugin to use wechat.

Features #

  • [X] Add Login
  • [X] Add Pay
  • [ ] Support LocalImage
  • [ ] Support 分享小程序

Install #

Add this to your package's pubspec.yaml file:

  flutter_wechat: "^0.1.5"

Getting Started #

  • Android
    • For Android, you must do the following before you can use the plugin:
      • Add the permissions to your AndroidManifest.xml
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.WRITE_SETTINGS" />
           如果想要响应微信resp需要在mainActivity同级目录下创建wxapi文件夹      下面新建WXEntryACtivity集成Activity      例如:
    private IWXAPI api;
    protected void onCreate(Bundle savedInstanceState) {
        api = WXAPIFactory.createWXAPI(this, "wxb25d3dec3db1affc", false);

    public void onReq(BaseReq baseReq) {


    public void onResp(BaseResp baseResp) {

    private void sendBroadcastToWechat(BaseResp baseResp) {
        Intent intent = new Intent();
        if (baseResp instanceof SendAuth.Resp) {
            SendAuth.Resp resp = (SendAuth.Resp) (baseResp);
            intent.putExtra("code", resp.errCode == 0 ? resp.code : "-1");
            intent.putExtra("type", "SendAuthResp");
        } else {
            intent.putExtra("code", baseResp.errCode + "");
            intent.putExtra("type", "ShareResp");
    protected void onNewIntent(Intent intent) {
        api.handleIntent(intent, this);
     // ios 8.x or older
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
     NSString * urlStr = [url absoluteString];
    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"WeChat" object:nil userInfo:@{@"url":urlStr}];
    return YES;

// ios 9.0+
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
            options:(NSDictionary<NSString*, id> *)options
    NSString * urlStr = [url absoluteString];
    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"WeChat" object:nil userInfo:@{@"url":urlStr}];
    return YES;

How to use #

import 'package:flutter_wechat/flutter_wechat.dart';
await FlutterWechat.registerWechat("wxxxxxx");// 微信注册需要在你需要的地方注册,最好是app首页
await FlutterWechat.shareText(text: "test", type:0,);//文字分享 type 0 聊天页面 1 朋友圈
await FlutterWechat.shareImage(imgUrl: "xxx", type:0,);
await FlutterWechat.shareMusic(imgUrl: "xxx", musicUrl:"",title:"",description:"",musicDataUrl:"",musicLowBandDataUrl:"",musicLowBandUrl:"",type:0,);
await FlutterWechat.shareVideo(imgUrl: "xxx", videoUrl:"",title:"",description:"",videoLowBandUrl:"",type:0,);
await FlutterWechat.shareWebPage(imgUrl: "xxx", webpageUrl:"",title:"",description:"",type:0,);
await FlutterWechat.login(scope:"",state:"");
await FlutterWechat.pay(partnerId: "",prepayId: "",nonceStr: "",timeStampe: "",sign: "",package: "",appId: "",);//具体参考微信参数传递

[0.0.1] - 2018.4.17

  • Support wechatShare.

[0.0.2] - 2018.4.18

  • change README.md

[0.0.7] - 2018.4.18

  • 移除调试输出

[0.0.9] - 2018.4.19

  • 增加微信登录

[0.1.0] - 2018.4.19

  • android ios统一返回

[0.1.2] - 2018.4.22

  • 支付

[0.1.5] - 2018.7.2

  • 删除测试Event回调

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_wechat: ^0.1.5

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_wechat/flutter_wechat.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Sep 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

13 out of 13 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/flutter_wechat.dart.

Run flutter format to format lib/flutter_wechat.dart.

Maintenance suggestions

Package is getting outdated. (-20.82 points)

The package was last published 63 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and flutter_wechat.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8