fake_tencent 0.0.1+1 copy "fake_tencent: ^0.0.1+1" to clipboard
fake_tencent: ^0.0.1+1 copied to clipboard

discontinuedreplaced by: tencent_kit
outdated

A powerful tencent plugin for Flutter.

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fake_tencent/fake_tencent.dart';

void main() {
  runZoned(() {
    runApp(MyApp());
  }, onError: (Object error, StackTrace stack) {
    print(error);
    print(stack);
  });

  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    FakeTencent tencent = FakeTencent();
    tencent.registerApp(appId: '222222');
    return FakeTencentProvider(
      tencent: tencent,
      child: MaterialApp(
        home: Home(tencent: tencent),
      ),
    );
  }
}

class Home extends StatefulWidget {
  Home({
    Key key,
    @required this.tencent,
  }) : super(key: key);

  final FakeTencent tencent;

  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  StreamSubscription<FakeTencentLoginResp> _login;
  StreamSubscription<FakeTencentUserInfoResp> _userInfo;
  StreamSubscription<FakeTencentShareResp> _share;

  @override
  void initState() {
    super.initState();
    _login = widget.tencent.loginResp().listen(_listenLogin);
    _userInfo = widget.tencent.userInfoResp().listen(_listenUserInfo);
    _share = widget.tencent.shareResp().listen(_listenShare);
  }

  void _listenLogin(FakeTencentLoginResp resp) {
    String content = 'login: ${resp.openId} - ${resp.accessToken}';
    _showTips('登录', content);
  }

  void _listenUserInfo(FakeTencentUserInfoResp resp) {
    String content = 'user info: ${resp.nickName} - ${resp.gender}';
    _showTips('用户', content);
  }

  void _listenShare(FakeTencentShareResp resp) {
    String content = 'share: ${resp.errorCode} - ${resp.errorMsg}';
    _showTips('分享', content);
  }

  @override
  void dispose() {
    if (_login != null) {
      _login.cancel();
    }
    if (_userInfo != null) {
      _userInfo.cancel();
    }
    if (_share != null) {
      _share.cancel();
    }
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Fake Tencent Demo'),
      ),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: const Text('环境检查'),
            onTap: () async {
              String content =
                  'tencent: ${await widget.tencent.isQQInstalled()} - ${await widget.tencent.isQQSupportSSOLogin()}';
              _showTips('环境检查', content);
            },
          ),
          ListTile(
            title: const Text('登录'),
            onTap: () {
              widget.tencent.login(
                scope: [FakeTencentScope.GET_SIMPLE_USERINFO],
              );
            },
          ),
          ListTile(
            title: const Text('获取用户信息'),
            onTap: () {
              widget.tencent.getUserInfo();
            },
          ),
          ListTile(
            title: const Text('分享文字'),
            onTap: () {
              widget.tencent.shareMood(
                scene: FakeTencentScene.SCENE_QZONE,
                summary: '分享测试',
              );
            },
          ),
          ListTile(
            title: const Text('分享链接'),
            onTap: () {
              widget.tencent.shareWebpage(
                scene: FakeTencentScene.SCENE_QQ,
                title: 'title',
                targetUrl: 'https://www.baidu.com/',
              );
            },
          ),
        ],
      ),
    );
  }

  void _showTips(String title, String content) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text(title),
          content: Text(content),
        );
      },
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

verified publisherhaitanyule.com

A powerful tencent plugin for Flutter.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, meta

More

Packages that depend on fake_tencent