mirror of
https://github.com/RxReader/tencent_kit.git
synced 2025-05-18 15:57:00 +08:00
fix
This commit is contained in:
@ -46,7 +46,7 @@ class _HomeState extends State<Home> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_respSubs = Tencent.respStream().listen(_listenLogin);
|
_respSubs = Tencent.instance.respStream().listen(_listenLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _listenLogin(BaseResp resp) {
|
void _listenLogin(BaseResp resp) {
|
||||||
@ -77,14 +77,14 @@ class _HomeState extends State<Home> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text('3.1.0 之后的版本请先获取权限'),
|
title: Text('3.1.0 之后的版本请先获取权限'),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await Tencent.setIsPermissionGranted(granted: true);
|
await Tencent.instance.setIsPermissionGranted(granted: true);
|
||||||
_showTips('授权', '已授权获取设备信息/同意隐私协议');
|
_showTips('授权', '已授权获取设备信息/同意隐私协议');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text('注册APP'),
|
title: Text('注册APP'),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await Tencent.registerApp(appId: _TENCENT_APPID);
|
await Tencent.instance.registerApp(appId: _TENCENT_APPID);
|
||||||
_showTips('注册APP', '注册成功');
|
_showTips('注册APP', '注册成功');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -92,14 +92,14 @@ class _HomeState extends State<Home> {
|
|||||||
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.instance.isQQInstalled()}\nTIM install: ${await Tencent.instance.isTIMInstalled()}';
|
||||||
_showTips('环境检查', content);
|
_showTips('环境检查', content);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text('登录'),
|
title: Text('登录'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Tencent.login(
|
Tencent.instance.login(
|
||||||
scope: <String>[TencentScope.GET_SIMPLE_USERINFO],
|
scope: <String>[TencentScope.GET_SIMPLE_USERINFO],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -145,7 +145,7 @@ class _HomeState extends State<Home> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text('分享说说'),
|
title: Text('分享说说'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Tencent.shareMood(
|
Tencent.instance.shareMood(
|
||||||
scene: TencentScene.SCENE_QZONE,
|
scene: TencentScene.SCENE_QZONE,
|
||||||
summary: '分享测试',
|
summary: '分享测试',
|
||||||
);
|
);
|
||||||
@ -154,7 +154,7 @@ class _HomeState extends State<Home> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text('文本分享'),
|
title: Text('文本分享'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Tencent.shareText(
|
Tencent.instance.shareText(
|
||||||
scene: TencentScene.SCENE_QQ,
|
scene: TencentScene.SCENE_QQ,
|
||||||
summary: '分享测试',
|
summary: '分享测试',
|
||||||
);
|
);
|
||||||
@ -165,7 +165,7 @@ class _HomeState extends State<Home> {
|
|||||||
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.instance.shareImage(
|
||||||
scene: TencentScene.SCENE_QQ,
|
scene: TencentScene.SCENE_QQ,
|
||||||
imageUri: Uri.file(file.path),
|
imageUri: Uri.file(file.path),
|
||||||
);
|
);
|
||||||
@ -174,7 +174,7 @@ class _HomeState extends State<Home> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text('网页分享'),
|
title: Text('网页分享'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Tencent.shareWebpage(
|
Tencent.instance.shareWebpage(
|
||||||
scene: TencentScene.SCENE_QQ,
|
scene: TencentScene.SCENE_QQ,
|
||||||
title: 'title',
|
title: 'title',
|
||||||
targetUrl: 'https://www.baidu.com/',
|
targetUrl: 'https://www.baidu.com/',
|
||||||
|
@ -1,141 +1,7 @@
|
|||||||
import 'package:tencent_kit/src/model/resp.dart';
|
|
||||||
import 'package:tencent_kit/src/tencent_constant.dart';
|
|
||||||
import 'package:tencent_kit/src/tencent_kit_platform_interface.dart';
|
import 'package:tencent_kit/src/tencent_kit_platform_interface.dart';
|
||||||
|
|
||||||
class Tencent {
|
class Tencent {
|
||||||
const Tencent._();
|
const Tencent._();
|
||||||
|
|
||||||
/// 设置是否已授权获取设备信息/是否同意隐私协议
|
static TencentKitPlatform get instance => TencentKitPlatform.instance;
|
||||||
static Future<void> setIsPermissionGranted({
|
|
||||||
required bool granted,
|
|
||||||
String? buildModel /* android.os.Build.MODEL */,
|
|
||||||
}) {
|
|
||||||
return TencentKitPlatform.instance.setIsPermissionGranted(
|
|
||||||
granted: granted,
|
|
||||||
buildModel: buildModel,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 向 Open_SDK 注册
|
|
||||||
static Future<void> registerApp({
|
|
||||||
required String appId,
|
|
||||||
String? universalLink,
|
|
||||||
}) {
|
|
||||||
return TencentKitPlatform.instance.registerApp(
|
|
||||||
appId: appId,
|
|
||||||
universalLink: universalLink,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 检查QQ是否已安装
|
|
||||||
static Future<bool> isQQInstalled() {
|
|
||||||
return TencentKitPlatform.instance.isQQInstalled();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 检查QQ是否已安装
|
|
||||||
static Future<bool> isTIMInstalled() {
|
|
||||||
return TencentKitPlatform.instance.isTIMInstalled();
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
static Stream<BaseResp> respStream() {
|
|
||||||
return TencentKitPlatform.instance.respStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 登录
|
|
||||||
static Future<void> login({
|
|
||||||
required List<String> scope,
|
|
||||||
}) {
|
|
||||||
return TencentKitPlatform.instance.login(scope: scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 登出
|
|
||||||
static Future<void> logout() {
|
|
||||||
return TencentKitPlatform.instance.logout();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 分享 - 说说
|
|
||||||
static Future<void> shareMood({
|
|
||||||
required int scene,
|
|
||||||
String? summary,
|
|
||||||
List<Uri>? imageUris,
|
|
||||||
Uri? videoUri,
|
|
||||||
}) {
|
|
||||||
return TencentKitPlatform.instance.shareMood(
|
|
||||||
scene: scene,
|
|
||||||
summary: summary,
|
|
||||||
imageUris: imageUris,
|
|
||||||
videoUri: videoUri,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 分享 - 文本(Android调用的是系统API,故而不会有回调)
|
|
||||||
static Future<void> shareText({
|
|
||||||
required int scene,
|
|
||||||
required String summary,
|
|
||||||
}) {
|
|
||||||
return TencentKitPlatform.instance.shareText(
|
|
||||||
scene: scene,
|
|
||||||
summary: summary,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 分享 - 图片
|
|
||||||
static Future<void> shareImage({
|
|
||||||
required int scene,
|
|
||||||
required Uri imageUri,
|
|
||||||
String? appName,
|
|
||||||
int extInt = TencentQZoneFlag.DEFAULT,
|
|
||||||
}) {
|
|
||||||
return TencentKitPlatform.instance.shareImage(
|
|
||||||
scene: scene,
|
|
||||||
imageUri: imageUri,
|
|
||||||
appName: appName,
|
|
||||||
extInt: extInt,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 分享 - 音乐
|
|
||||||
static Future<void> shareMusic({
|
|
||||||
required int scene,
|
|
||||||
required String title,
|
|
||||||
String? summary,
|
|
||||||
Uri? imageUri,
|
|
||||||
required String musicUrl,
|
|
||||||
required String targetUrl,
|
|
||||||
String? appName,
|
|
||||||
int extInt = TencentQZoneFlag.DEFAULT,
|
|
||||||
}) {
|
|
||||||
return TencentKitPlatform.instance.shareMusic(
|
|
||||||
scene: scene,
|
|
||||||
title: title,
|
|
||||||
summary: summary,
|
|
||||||
imageUri: imageUri,
|
|
||||||
musicUrl: musicUrl,
|
|
||||||
targetUrl: targetUrl,
|
|
||||||
appName: appName,
|
|
||||||
extInt: extInt,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 分享 - 网页
|
|
||||||
static Future<void> shareWebpage({
|
|
||||||
required int scene,
|
|
||||||
required String title,
|
|
||||||
String? summary,
|
|
||||||
Uri? imageUri,
|
|
||||||
required String targetUrl,
|
|
||||||
String? appName,
|
|
||||||
int extInt = TencentQZoneFlag.DEFAULT,
|
|
||||||
}) {
|
|
||||||
return TencentKitPlatform.instance.shareWebpage(
|
|
||||||
scene: scene,
|
|
||||||
title: title,
|
|
||||||
summary: summary,
|
|
||||||
imageUri: imageUri,
|
|
||||||
targetUrl: targetUrl,
|
|
||||||
appName: appName,
|
|
||||||
extInt: extInt,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,11 @@ class MethodChannelTencentKit extends TencentKitPlatform {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Stream<BaseResp> respStream() {
|
||||||
|
return _respStreamController.stream;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> isQQInstalled() async {
|
Future<bool> isQQInstalled() async {
|
||||||
return await methodChannel.invokeMethod<bool>('isQQInstalled') ?? false;
|
return await methodChannel.invokeMethod<bool>('isQQInstalled') ?? false;
|
||||||
@ -68,11 +73,6 @@ class MethodChannelTencentKit extends TencentKitPlatform {
|
|||||||
return await methodChannel.invokeMethod<bool>('isTIMInstalled') ?? false;
|
return await methodChannel.invokeMethod<bool>('isTIMInstalled') ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Stream<BaseResp> respStream() {
|
|
||||||
return _respStreamController.stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> login({
|
Future<void> login({
|
||||||
required List<String> scope,
|
required List<String> scope,
|
||||||
|
@ -24,6 +24,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
_instance = instance;
|
_instance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 设置是否已授权获取设备信息/是否同意隐私协议
|
||||||
Future<void> setIsPermissionGranted({
|
Future<void> setIsPermissionGranted({
|
||||||
required bool granted,
|
required bool granted,
|
||||||
String? buildModel /* android.os.Build.MODEL */,
|
String? buildModel /* android.os.Build.MODEL */,
|
||||||
@ -32,6 +33,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
'setIsPermissionGranted({required granted, buildModel}) has not been implemented.');
|
'setIsPermissionGranted({required granted, buildModel}) has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 向 Open_SDK 注册
|
||||||
Future<void> registerApp({
|
Future<void> registerApp({
|
||||||
required String appId,
|
required String appId,
|
||||||
String? universalLink,
|
String? universalLink,
|
||||||
@ -40,18 +42,22 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
'registerApp({required appId, universalLink}) has not been implemented.');
|
'registerApp({required appId, universalLink}) has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isQQInstalled() {
|
///
|
||||||
throw UnimplementedError('isQQInstalled() has not been implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> isTIMInstalled() {
|
|
||||||
throw UnimplementedError('isTIMInstalled() has not been implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
Stream<BaseResp> respStream() {
|
Stream<BaseResp> respStream() {
|
||||||
throw UnimplementedError('respStream() has not been implemented.');
|
throw UnimplementedError('respStream() has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 检查QQ是否已安装
|
||||||
|
Future<bool> isQQInstalled() {
|
||||||
|
throw UnimplementedError('isQQInstalled() has not been implemented.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 检查QQ是否已安装
|
||||||
|
Future<bool> isTIMInstalled() {
|
||||||
|
throw UnimplementedError('isTIMInstalled() has not been implemented.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 登录
|
||||||
Future<void> login({
|
Future<void> login({
|
||||||
required List<String> scope,
|
required List<String> scope,
|
||||||
}) {
|
}) {
|
||||||
@ -59,10 +65,12 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
'login({required scope}) has not been implemented.');
|
'login({required scope}) has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 登出
|
||||||
Future<void> logout() {
|
Future<void> logout() {
|
||||||
throw UnimplementedError('logout() has not been implemented.');
|
throw UnimplementedError('logout() has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 分享 - 说说
|
||||||
Future<void> shareMood({
|
Future<void> shareMood({
|
||||||
required int scene,
|
required int scene,
|
||||||
String? summary,
|
String? summary,
|
||||||
@ -73,6 +81,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
'shareMood({required scene, summary, imageUris, videoUri}) has not been implemented.');
|
'shareMood({required scene, summary, imageUris, videoUri}) has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 分享 - 文本(Android调用的是系统API,故而不会有回调)
|
||||||
Future<void> shareText({
|
Future<void> shareText({
|
||||||
required int scene,
|
required int scene,
|
||||||
required String summary,
|
required String summary,
|
||||||
@ -81,6 +90,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
'shareText({required scene, required summary}) has not been implemented.');
|
'shareText({required scene, required summary}) has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 分享 - 图片
|
||||||
Future<void> shareImage({
|
Future<void> shareImage({
|
||||||
required int scene,
|
required int scene,
|
||||||
required Uri imageUri,
|
required Uri imageUri,
|
||||||
@ -91,6 +101,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
'shareImage({required scene, required imageUri, appName, extInt}) has not been implemented.');
|
'shareImage({required scene, required imageUri, appName, extInt}) has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 分享 - 音乐
|
||||||
Future<void> shareMusic({
|
Future<void> shareMusic({
|
||||||
required int scene,
|
required int scene,
|
||||||
required String title,
|
required String title,
|
||||||
@ -105,6 +116,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
'shareMusic({required scene, required title, summary, imageUri, required musicUrl, required targetUrl, appName, extInt}) has not been implemented.');
|
'shareMusic({required scene, required title, summary, imageUri, required musicUrl, required targetUrl, appName, extInt}) has not been implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 分享 - 网页
|
||||||
Future<void> shareWebpage({
|
Future<void> shareWebpage({
|
||||||
required int scene,
|
required int scene,
|
||||||
required String title,
|
required String title,
|
||||||
|
@ -121,6 +121,6 @@ void main() {
|
|||||||
final MockTencentKitPlatform fakePlatform = MockTencentKitPlatform();
|
final MockTencentKitPlatform fakePlatform = MockTencentKitPlatform();
|
||||||
TencentKitPlatform.instance = fakePlatform;
|
TencentKitPlatform.instance = fakePlatform;
|
||||||
|
|
||||||
expect(await Tencent.isQQInstalled(), true);
|
expect(await Tencent.instance.isQQInstalled(), true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user