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

View File

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

View File

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