From c61a111ef243990ff99b76a60387e9b7f42e2728 Mon Sep 17 00:00:00 2001 From: v7lin Date: Sat, 31 Jul 2021 20:11:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 29 ++++++++++++--------------- example/lib/model/weibo_api_resp.dart | 1 - example/lib/weibo.dart | 1 - 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 99ced1a..e7ed64d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -42,33 +42,30 @@ class Home extends StatefulWidget { } class _HomeState extends State { - late final StreamSubscription _auth = - Weibo.instance.authResp().listen(_listenAuth); - late final StreamSubscription _share = - Weibo.instance.shareMsgResp().listen(_listenShareMsg); + late final StreamSubscription _respSubs = + Weibo.instance.respStream().listen(_listenResp); - WeiboAuthResp? _authResp; + AuthResp? _authResp; @override void initState() { super.initState(); } - void _listenAuth(WeiboAuthResp resp) { - _authResp = resp; - final String content = 'auth: ${resp.errorCode}'; - _showTips('登录', content); - } - - void _listenShareMsg(WeiboSdkResp resp) { - final String content = 'share: ${resp.errorCode}'; - _showTips('分享', content); + void _listenResp(BaseResp resp) { + if (resp is AuthResp) { + _authResp = resp; + final String content = 'auth: ${resp.errorCode}'; + _showTips('登录', content); + } else if (resp is ShareMsgResp) { + final String content = 'share: ${resp.errorCode}'; + _showTips('分享', content); + } } @override void dispose() { - _auth.cancel(); - _share.cancel(); + _respSubs.cancel(); super.dispose(); } diff --git a/example/lib/model/weibo_api_resp.dart b/example/lib/model/weibo_api_resp.dart index d456019..17f1ee2 100644 --- a/example/lib/model/weibo_api_resp.dart +++ b/example/lib/model/weibo_api_resp.dart @@ -82,4 +82,3 @@ class WeiboUserInfoResp extends WeiboApiResp { Map toJson() => _$WeiboUserInfoRespToJson(this); } - diff --git a/example/lib/weibo.dart b/example/lib/weibo.dart index 455055a..ebdee1a 100644 --- a/example/lib/weibo.dart +++ b/example/lib/weibo.dart @@ -6,7 +6,6 @@ import 'package:weibo_kit/weibo_kit.dart'; import 'package:weibo_kit_example/model/weibo_api_resp.dart'; extension ApiWeibo on Weibo { - /// 用户信息 Future getUserInfo({ required String appkey,