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