From c92aa6136d7c0d5d01f4e716b5dc1a1894d87468 Mon Sep 17 00:00:00 2001 From: v7lin Date: Fri, 17 May 2019 10:44:14 +0800 Subject: [PATCH] xxx --- example/lib/main.dart | 38 ++++++++++++++--------------------- lib/fake_tencent.dart | 1 - lib/src/tencent.dart | 4 ++-- lib/src/tencent_provider.dart | 23 --------------------- pubspec.yaml | 2 +- 5 files changed, 18 insertions(+), 50 deletions(-) delete mode 100644 lib/src/tencent_provider.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 9e235bc..b84094c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -25,25 +25,13 @@ void main() { class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - Tencent tencent = Tencent(); - tencent.registerApp(appId: '222222'); - return TencentProvider( - tencent: tencent, - child: MaterialApp( - home: Home(tencent: tencent), - ), + return MaterialApp( + home: Home(), ); } } class Home extends StatefulWidget { - Home({ - Key key, - @required this.tencent, - }) : super(key: key); - - final Tencent tencent; - @override State createState() { return _HomeState(); @@ -51,6 +39,8 @@ class Home extends StatefulWidget { } class _HomeState extends State { + Tencent _tencent; + StreamSubscription _login; StreamSubscription _userInfo; StreamSubscription _share; @@ -60,9 +50,11 @@ class _HomeState extends State { @override void initState() { super.initState(); - _login = widget.tencent.loginResp().listen(_listenLogin); - _userInfo = widget.tencent.userInfoResp().listen(_listenUserInfo); - _share = widget.tencent.shareResp().listen(_listenShare); + _tencent = Tencent(); + _tencent.registerApp(appId: '222222'); + _login = _tencent.loginResp().listen(_listenLogin); + _userInfo = _tencent.userInfoResp().listen(_listenUserInfo); + _share = _tencent.shareResp().listen(_listenShare); } void _listenLogin(TencentLoginResp resp) { @@ -107,14 +99,14 @@ class _HomeState extends State { title: const Text('环境检查'), onTap: () async { String content = - 'tencent: ${await widget.tencent.isQQInstalled()} - ${await widget.tencent.isQQSupportSSOLogin()}'; + 'tencent: ${await _tencent.isQQInstalled()} - ${await _tencent.isQQSupportSSOLogin()}'; _showTips('环境检查', content); }, ), ListTile( title: const Text('登录'), onTap: () { - widget.tencent.login( + _tencent.login( scope: [TencentScope.GET_SIMPLE_USERINFO], ); }, @@ -127,7 +119,7 @@ class _HomeState extends State { if (DateTime.now().millisecondsSinceEpoch - _loginResp.createAt < _loginResp.expiresIn * 1000) { - widget.tencent.getUserInfo( + _tencent.getUserInfo( openId: _loginResp.openid, accessToken: _loginResp.accessToken, expiresIn: _loginResp.expiresIn, @@ -140,7 +132,7 @@ class _HomeState extends State { ListTile( title: const Text('分享文字'), onTap: () { - widget.tencent.shareMood( + _tencent.shareMood( scene: TencentScene.SCENE_QZONE, summary: '分享测试', ); @@ -160,7 +152,7 @@ class _HomeState extends State { saveFile.writeAsBytesSync(imageData.buffer.asUint8List(), flush: true); } - await widget.tencent.shareImage( + await _tencent.shareImage( scene: TencentScene.SCENE_QQ, imageUri: Uri.file(saveFile.path), ); @@ -169,7 +161,7 @@ class _HomeState extends State { ListTile( title: const Text('分享链接'), onTap: () { - widget.tencent.shareWebpage( + _tencent.shareWebpage( scene: TencentScene.SCENE_QQ, title: 'title', targetUrl: 'https://www.baidu.com/', diff --git a/lib/fake_tencent.dart b/lib/fake_tencent.dart index 44a56a4..0097815 100644 --- a/lib/fake_tencent.dart +++ b/lib/fake_tencent.dart @@ -6,7 +6,6 @@ export 'src/domain/tencent_share_resp.dart' hide TencentShareRespSerializer; export 'src/domain/tencent_user_info_resp.dart' hide TencentUserInfoRespSerializer; export 'src/tencent.dart'; -export 'src/tencent_provider.dart'; export 'src/tencent_qzone_flag.dart'; export 'src/tencent_scene.dart'; export 'src/tencent_scope.dart'; diff --git a/lib/src/tencent.dart b/lib/src/tencent.dart index 5d7f184..d214cc4 100644 --- a/lib/src/tencent.dart +++ b/lib/src/tencent.dart @@ -43,8 +43,8 @@ class Tencent { static const String _SCHEME_FILE = 'file'; - static const MethodChannel _channel = - MethodChannel('v7lin.github.io/fake_tencent'); + final MethodChannel _channel = + const MethodChannel('v7lin.github.io/fake_tencent'); final StreamController _loginRespStreamController = StreamController.broadcast(); diff --git a/lib/src/tencent_provider.dart b/lib/src/tencent_provider.dart deleted file mode 100644 index 89e6949..0000000 --- a/lib/src/tencent_provider.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:fake_tencent/src/tencent.dart'; -import 'package:flutter/widgets.dart'; - -class TencentProvider extends InheritedWidget { - TencentProvider({ - Key key, - @required this.tencent, - @required Widget child, - }) : super(key: key, child: child); - - final Tencent tencent; - - @override - bool updateShouldNotify(InheritedWidget oldWidget) { - TencentProvider oldProvider = oldWidget as TencentProvider; - return tencent != oldProvider.tencent; - } - - static TencentProvider of(BuildContext context) { - return context.inheritFromWidgetOfExactType(TencentProvider) - as TencentProvider; - } -} diff --git a/pubspec.yaml b/pubspec.yaml index e6c197a..e478759 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fake_tencent description: A powerful tencent plugin for Flutter. -version: 0.2.0+1 +version: 0.3.0 author: v7lin homepage: https://github.com/v7lin/fake_tencent