flutter_wechat 0.0.9

flutter_wechat #

A flutter plugin to use wechat.

Features #

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

Install #

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

dependencies:
  flutter_wechat: "^0.0.7"

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;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, "wxb25d3dec3db1affc", false);
        onNewIntent(getIntent());
        finish();
    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp baseResp) {
        String toastString = "";
        switch (baseResp.errCode) {
            case 0:
                toastString = "操作成功";
                if (baseResp instanceof SendAuth.Resp) {
                    SendAuth.Resp newResp = (SendAuth.Resp) baseResp;
                    //获取微信传回的code
                    String code = newResp.code;
                    FlutterWechatPlugin.setCode(code);
                }
                break;
            case -1:
                toastString = "一般错误";
                break;
            case -2:
                toastString = "取消操作";
                break;
            case -3:
                toastString = "发送失败";
                break;
            case -4:
                toastString = "认证拒绝";
                break;
            case -5:
                toastString = "帐号禁用";
                break;
        }
        Toast.makeText(this, toastString, Toast.LENGTH_SHORT).show();
    }

    protected void onNewIntent(Intent intent) {
        api.handleIntent(intent, this);
    }

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:"");


[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

  • 增加微信登录

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_wechat/flutter_wechat.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  initState() {
    super.initState();
    initPlatformState();
  }

  initPlatformState() async {
    await FlutterWechat.registerWechat("wxb25d3dec3db1affc");
    await FlutterWechat.login();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        body: new Center(
          child: new Text('test'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_wechat: ^0.0.9

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
47
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

10 out of 10 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. (-22.74 points)

The package was last published 64 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.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

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
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8

Admin