This commit is contained in:
v7lin
2022-05-17 14:25:47 +08:00
parent 9f56099735
commit 2d8df1a91e
3 changed files with 23 additions and 30 deletions

View File

@ -34,8 +34,8 @@ abstract class TencentApiResp {
) )
class TencentUserInfoResp extends TencentApiResp { class TencentUserInfoResp extends TencentApiResp {
const TencentUserInfoResp({ const TencentUserInfoResp({
required int ret, required super.ret,
String? msg, super.msg,
this.isLost, this.isLost,
this.nickname, this.nickname,
this.gender, this.gender,
@ -56,7 +56,7 @@ class TencentUserInfoResp extends TencentApiResp {
this.yellowVipLevel, this.yellowVipLevel,
this.level, this.level,
this.isYellowYearVip, this.isYellowYearVip,
}) : super(ret: ret, msg: msg); });
factory TencentUserInfoResp.fromJson(Map<String, dynamic> json) => factory TencentUserInfoResp.fromJson(Map<String, dynamic> json) =>
_$TencentUserInfoRespFromJson(json); _$TencentUserInfoRespFromJson(json);

View File

@ -15,7 +15,9 @@ void main() {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const MyApp({
super.key,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -26,7 +28,9 @@ class MyApp extends StatelessWidget {
} }
class Home extends StatefulWidget { class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key); const Home({
super.key,
});
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -87,8 +91,7 @@ class _HomeState extends State<Home> {
ListTile( ListTile(
title: Text('环境检查'), title: Text('环境检查'),
onTap: () async { onTap: () async {
final String content = final String content = 'QQ install: ${await Tencent.isQQInstalled()}\nTIM install: ${await Tencent.isTIMInstalled()}';
'QQ install: ${await Tencent.isQQInstalled()}\nTIM install: ${await Tencent.isTIMInstalled()}';
_showTips('环境检查', content); _showTips('环境检查', content);
}, },
), ),
@ -103,17 +106,14 @@ class _HomeState extends State<Home> {
ListTile( ListTile(
title: Text('获取用户信息'), title: Text('获取用户信息'),
onTap: () async { onTap: () async {
if ((_loginResp?.isSuccessful ?? false) && if ((_loginResp?.isSuccessful ?? false) && !(_loginResp!.isExpired ?? true)) {
!(_loginResp!.isExpired ?? true)) { final TencentUserInfoResp userInfo = await TencentApi.getUserInfo(
final TencentUserInfoResp userInfo =
await TencentApi.getUserInfo(
appId: _TENCENT_APPID, appId: _TENCENT_APPID,
openid: _loginResp!.openid!, openid: _loginResp!.openid!,
accessToken: _loginResp!.accessToken!, accessToken: _loginResp!.accessToken!,
); );
if (userInfo.isSuccessful) { if (userInfo.isSuccessful) {
_showTips('用户信息', _showTips('用户信息', '${userInfo.nickname} - ${userInfo.gender} - ${userInfo.genderType}');
'${userInfo.nickname} - ${userInfo.gender} - ${userInfo.genderType}');
} else { } else {
_showTips('用户信息', '${userInfo.ret} - ${userInfo.msg}'); _showTips('用户信息', '${userInfo.ret} - ${userInfo.msg}');
} }
@ -123,17 +123,14 @@ class _HomeState extends State<Home> {
ListTile( ListTile(
title: Text('获取UnionID'), title: Text('获取UnionID'),
onTap: () async { onTap: () async {
if ((_loginResp?.isSuccessful ?? false) && if ((_loginResp?.isSuccessful ?? false) && !(_loginResp!.isExpired ?? true)) {
!(_loginResp!.isExpired ?? true)) {
final TencentUnionidResp unionid = await TencentApi.getUnionId( final TencentUnionidResp unionid = await TencentApi.getUnionId(
accessToken: _loginResp!.accessToken!, accessToken: _loginResp!.accessToken!,
); );
if (unionid.isSuccessful) { if (unionid.isSuccessful) {
_showTips('UnionID', _showTips('UnionID', '${unionid.clientId} - ${unionid.openid} - ${unionid.unionid}');
'${unionid.clientId} - ${unionid.openid} - ${unionid.unionid}');
} else { } else {
_showTips('UnionID', _showTips('UnionID', '${unionid.error} - ${unionid.errorDescription}');
'${unionid.error} - ${unionid.errorDescription}');
} }
} }
}, },
@ -159,8 +156,7 @@ class _HomeState extends State<Home> {
ListTile( ListTile(
title: Text('图片分享'), title: Text('图片分享'),
onTap: () async { onTap: () async {
final File file = await DefaultCacheManager().getSingleFile( final File file = await DefaultCacheManager().getSingleFile('https://www.baidu.com/img/bd_logo1.png?where=super');
'https://www.baidu.com/img/bd_logo1.png?where=super');
await Tencent.shareImage( await Tencent.shareImage(
scene: TencentScene.SCENE_QQ, scene: TencentScene.SCENE_QQ,
imageUri: Uri.file(file.path), imageUri: Uri.file(file.path),

View File

@ -43,13 +43,13 @@ abstract class BaseResp {
) )
class LoginResp extends BaseResp { class LoginResp extends BaseResp {
const LoginResp({ const LoginResp({
required int ret, required super.ret,
String? msg, super.msg,
this.openid, this.openid,
this.accessToken, this.accessToken,
this.expiresIn, this.expiresIn,
this.createAt, this.createAt,
}) : super(ret: ret, msg: msg); });
factory LoginResp.fromJson(Map<String, dynamic> json) => factory LoginResp.fromJson(Map<String, dynamic> json) =>
_$LoginRespFromJson(json); _$LoginRespFromJson(json);
@ -73,12 +73,9 @@ class LoginResp extends BaseResp {
) )
class ShareMsgResp extends BaseResp { class ShareMsgResp extends BaseResp {
const ShareMsgResp({ const ShareMsgResp({
required int ret, required super.ret,
String? msg, super.msg,
}) : super( });
ret: ret,
msg: msg,
);
factory ShareMsgResp.fromJson(Map<String, dynamic> json) => factory ShareMsgResp.fromJson(Map<String, dynamic> json) =>
_$ShareMsgRespFromJson(json); _$ShareMsgRespFromJson(json);