flutter_qq_bridge 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 51

flutter_qq_bridge #

支持 Android / iOS:

1.登录 2.获取用户基本信息 3.分享(目前仅支持新闻类型)

Update #

version 0.0.2 -> 添加 TencentOpenAPI.framework

Getting Started #

1. 环境配置 #

Android #

AndroidManifest #
...

<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"/>

...

<activity
    android:name="com.tencent.connect.common.AssistActivity"
    android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="behind"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
    android:name="com.tencent.tauth.AuthActivity"
    android:launchMode="singleTask"
    android:noHistory="true" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="tencent${your app_id}" />
    </intent-filter>
</activity>

iOS #

详情请参考腾讯官方文档及网络上更多优秀解答

2. Flutter 中使用 #

import 'package:flutter_qq_bridge/flutter_qq_bridge.dart';

① 初始化 #

await FlutterQqBridge.registerQq('$androidAppId', '$iOSAppId');

② QQ 登录 #

var res = await FlutterQqBridge.login();

if (res.code == 0) { // success
  _tencent = Tencent.fromJson(res.message);
  
  // update UI
  setState(() {
    _loginRes = 'openId:${_tencent.openId}, accessToken:${_tencent.accessToken}, expires:${_tencent.expiresTime}';
  });
}

③ 获取用户基本信息(登录之后) #

if (_tencent != null) { // _tencent from login success
  var res = await FlutterQqBridge.getUserInfo(_tencent);
  if (res.code == 0) {
    _qqUser = QqUser.fromJson(res.message);
    
    // update UI
    setState(() {
      _userInfo = 'nickname:${_qqUser.nickname}, '
          'gender:${_qqUser.gender}, '
          'year:${_qqUser.year}, '
          'province:${_qqUser.province}, '
          'city:${_qqUser.city}, '
          'figureurl:${_qqUser.figureurl},';
    });
  }
}

④ 分享 #

分享给好友:

var res = await FlutterQqBridge.shareToQQ(ShareQQContent(
  title: 'Remeet-只有00后的脱单神器',
  summary: '我们只想做个简单干净的聊天软件,帮你遇见喜欢的人。',
  targetUrl: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.haisong.remeet',
  imageUrl: 'http://pp.myapp.com/ma_icon/0/icon_52621236_1517135649/96',
  appName: 'Remeet',
));

// update UI
setState(() {
  _shareQqRes = 'share -> code: ${res.code}, message:${res.message}';
});

分享到 QQ 空间:

var res = await FlutterQqBridge.shareToQzone(ShareQqContent(
  title: 'Remeet-只有00后的脱单神器',
  summary: '我们只想做个简单干净的聊天软件,帮你遇见喜欢的人。',
  targetUrl: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.haisong.remeet',
  imageUrl: 'http://pp.myapp.com/ma_icon/0/icon_52621236_1517135649/96',
  appName: 'Remeet',
));

setState(() {
  _shareQzoneRes = 'share -> code: ${res.code}, message:${res.message}';
});

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

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

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

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

class _MyAppState extends State<MyApp> {
  String _loginRes = 'Unknown';
  String _shareQqRes = 'Unknown';
  String _shareQzoneRes = 'Unknown';
  String _userInfo = 'Unknown';

  Tencent _tencent;
  QqUser _qqUser;

  _login() async {
    var res = await FlutterQqBridge.login();

    if (res.code == 0) {
      _tencent = Tencent.fromJson(res.message);
      setState(() {
        _loginRes = 'openId:${_tencent.openId}, accessToken:${_tencent.accessToken}, expires:${_tencent.expiresTime}';
      });
    }
  }

  _shareQq() async {
    var res = await FlutterQqBridge.shareToQQ(ShareQqContent(
      title: 'Remeet-只有00后的脱单神器',
      summary: '我们只想做个简单干净的聊天软件,帮你遇见喜欢的人。',
      targetUrl: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.haisong.remeet',
      imageUrl: 'http://pp.myapp.com/ma_icon/0/icon_52621236_1517135649/96',
      appName: 'Remeet',
    ));

    setState(() {
      _shareQqRes = 'share -> code: ${res.code}, message:${res.message}';
    });
  }

  _shareQzone() async {
    var res = await FlutterQqBridge.shareToQzone(ShareQqContent(
      title: 'Remeet-只有00后的脱单神器',
      summary: '我们只想做个简单干净的聊天软件,帮你遇见喜欢的人。',
      targetUrl: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.haisong.remeet',
      imageUrl: 'http://pp.myapp.com/ma_icon/0/icon_52621236_1517135649/96',
      appName: 'Remeet',
    ));

    setState(() {
      _shareQzoneRes = 'share -> code: ${res.code}, message:${res.message}';
    });
  }

  _user() async {
    if (_tencent != null) {
      var res = await FlutterQqBridge.getUserInfo(_tencent);
      if (res.code == 0) {
        _qqUser = QqUser.fromJson(res.message);
        setState(() {
          _userInfo = 'nickname:${_qqUser.nickname}, '
              'gender:${_qqUser.gender}, '
              'year:${_qqUser.year}, '
              'province:${_qqUser.province}, '
              'city:${_qqUser.city}, '
              'figureurl:${_qqUser.figureurl},';
        });
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    FlutterQqBridge.registerQq('1107027380', '1106056827');
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Padding(padding: EdgeInsets.all(30.0),
                  child: GestureDetector(
                    onTap: _login,
                    child: Text('qq login \n $_loginRes', style: TextStyle(fontSize: 20.0, color: Colors.black),),
                  )
              ),

              Padding(padding: EdgeInsets.all(30.0),
                  child: GestureDetector(
                    onTap: _user,
                    child: Text('qq user \n $_userInfo', style: TextStyle(fontSize: 20.0, color: Colors.black),),
                  )
              ),

              Padding(padding: EdgeInsets.all(30.0),
                  child: GestureDetector(
                    onTap: _shareQq,
                    child: Text('qq share \n $_shareQqRes', style: TextStyle(fontSize: 20.0, color: Colors.black),),
                  )
              ),

              Padding(padding: EdgeInsets.all(30.0),
                  child: GestureDetector(
                    onTap: _shareQzone,
                    child: Text('qzone share \n $_shareQzoneRes', style: TextStyle(fontSize: 20.0, color: Colors.black),),
                  )
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_qq_bridge: ^0.0.3

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_qq_bridge/flutter_qq_bridge.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
17
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
65
Overall:
Weighted score of the above. [more]
51
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

53 out of 53 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.

Fix lib/flutter_qq_bridge.dart. (-1 points)

Analysis of lib/flutter_qq_bridge.dart reported 2 hints:

line 129 col 9: Name non-constant identifiers using lowerCamelCase.

line 139 col 9: Name non-constant identifiers using lowerCamelCase.

Maintenance suggestions

Package is getting outdated. (-15.62 points)

The package was last published 60 weeks ago.

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.

The package description is too short. (-9 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.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