format
This commit is contained in:
parent
f306734e7b
commit
7742eefd28
@ -95,7 +95,8 @@ class _HomeState extends State<Home> {
|
||||
ListTile(
|
||||
title: Text('环境检查'),
|
||||
onTap: () async {
|
||||
final String content = 'weibo: ${await Weibo.instance.isInstalled()}';
|
||||
final String content =
|
||||
'weibo: ${await Weibo.instance.isInstalled()}';
|
||||
_showTips('环境检查', content);
|
||||
},
|
||||
),
|
||||
@ -112,15 +113,18 @@ class _HomeState extends State<Home> {
|
||||
title: Text('用户信息'),
|
||||
onTap: () async {
|
||||
if (_authResp?.isSuccessful ?? false) {
|
||||
final WeiboUserInfoResp userInfoResp = await WeiboApi.getUserInfo(
|
||||
final WeiboUserInfoResp userInfoResp =
|
||||
await WeiboApi.getUserInfo(
|
||||
appkey: _WEIBO_APP_KEY,
|
||||
userId: _authResp!.userId!,
|
||||
accessToken: _authResp!.accessToken!,
|
||||
);
|
||||
if (userInfoResp.isSuccessful) {
|
||||
_showTips('用户信息', '${userInfoResp.screenName}\n${userInfoResp.description}\n${userInfoResp.location}\n${userInfoResp.profileImageUrl}');
|
||||
_showTips('用户信息',
|
||||
'${userInfoResp.screenName}\n${userInfoResp.description}\n${userInfoResp.location}\n${userInfoResp.profileImageUrl}');
|
||||
} else {
|
||||
_showTips('用户信息', '获取用户信息失败\n${userInfoResp.errorCode}:${userInfoResp.error}');
|
||||
_showTips('用户信息',
|
||||
'获取用户信息失败\n${userInfoResp.errorCode}:${userInfoResp.error}');
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -136,15 +140,19 @@ class _HomeState extends State<Home> {
|
||||
ListTile(
|
||||
title: Text('图片分享'),
|
||||
onTap: () async {
|
||||
File file = await DefaultCacheManager().getSingleFile('https://www.baidu.com/img/bd_logo1.png?where=super');
|
||||
File file = await DefaultCacheManager().getSingleFile(
|
||||
'https://www.baidu.com/img/bd_logo1.png?where=super');
|
||||
if (Platform.isAndroid) {
|
||||
// 仅支持 Context.getExternalFilesDir(null)/Context.getExternalCacheDirs(null) 路径分享
|
||||
// path_provider.getExternalCacheDirectories();
|
||||
// path_provider.getExternalStorageDirectory();
|
||||
final Directory temporaryDir = await path_provider.getTemporaryDirectory();
|
||||
final Directory temporaryDir =
|
||||
await path_provider.getTemporaryDirectory();
|
||||
if (path.isWithin(temporaryDir.parent.path, file.path)) {
|
||||
// 复制
|
||||
final File copyFile = File(path.join((await path_provider.getExternalStorageDirectory())!.path, path.basename(file.path)));
|
||||
final File copyFile = File(path.join(
|
||||
(await path_provider.getExternalStorageDirectory())!.path,
|
||||
path.basename(file.path)));
|
||||
if (copyFile.existsSync()) {
|
||||
await copyFile.delete();
|
||||
}
|
||||
@ -161,11 +169,14 @@ 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 imglib.Image thumbnail = imglib.decodeImage(file.readAsBytesSync())!;
|
||||
final File file = await DefaultCacheManager().getSingleFile(
|
||||
'https://www.baidu.com/img/bd_logo1.png?where=super');
|
||||
final imglib.Image thumbnail =
|
||||
imglib.decodeImage(file.readAsBytesSync())!;
|
||||
Uint8List thumbData = thumbnail.getBytes();
|
||||
if (thumbData.length > 32 * 1024) {
|
||||
thumbData = Uint8List.fromList(imglib.encodeJpg(thumbnail, quality: 100 * 32 * 1024 ~/ thumbData.length));
|
||||
thumbData = Uint8List.fromList(imglib.encodeJpg(thumbnail,
|
||||
quality: 100 * 32 * 1024 ~/ thumbData.length));
|
||||
}
|
||||
await Weibo.instance.shareWebpage(
|
||||
title: 'title',
|
||||
|
@ -12,16 +12,21 @@ import 'package:weibo_kit/src/weibo_kit_platform_interface.dart';
|
||||
class MethodChannelWeiboKit extends WeiboKitPlatform {
|
||||
/// The method channel used to interact with the native platform.
|
||||
@visibleForTesting
|
||||
late final MethodChannel methodChannel = const MethodChannel('v7lin.github.io/weibo_kit')..setMethodCallHandler(_handleMethod);
|
||||
final StreamController<BaseResp> _respStreamController = StreamController<BaseResp>.broadcast();
|
||||
late final MethodChannel methodChannel =
|
||||
const MethodChannel('v7lin.github.io/weibo_kit')
|
||||
..setMethodCallHandler(_handleMethod);
|
||||
final StreamController<BaseResp> _respStreamController =
|
||||
StreamController<BaseResp>.broadcast();
|
||||
|
||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case 'onAuthResp':
|
||||
_respStreamController.add(AuthResp.fromJson((call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
_respStreamController.add(AuthResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
case 'onShareMsgResp':
|
||||
_respStreamController.add(ShareMsgResp.fromJson((call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
_respStreamController.add(ShareMsgResp.fromJson(
|
||||
(call.arguments as Map<dynamic, dynamic>).cast<String, dynamic>()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -57,7 +62,8 @@ class MethodChannelWeiboKit extends WeiboKitPlatform {
|
||||
|
||||
@override
|
||||
Future<bool> isSupportMultipleImage() async {
|
||||
return await methodChannel.invokeMethod<bool>('isSupportMultipleImage') ?? false;
|
||||
return await methodChannel.invokeMethod<bool>('isSupportMultipleImage') ??
|
||||
false;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -99,7 +105,10 @@ class MethodChannelWeiboKit extends WeiboKitPlatform {
|
||||
}) {
|
||||
assert(text == null || text.length <= 1024);
|
||||
assert((imageData != null && imageData.lengthInBytes <= 2 * 1024 * 1024) ||
|
||||
(imageUri != null && imageUri.isScheme('file') && imageUri.toFilePath().length <= 512 && File.fromUri(imageUri).lengthSync() <= 10 * 1024 * 1024));
|
||||
(imageUri != null &&
|
||||
imageUri.isScheme('file') &&
|
||||
imageUri.toFilePath().length <= 512 &&
|
||||
File.fromUri(imageUri).lengthSync() <= 10 * 1024 * 1024));
|
||||
return methodChannel.invokeMethod<void>(
|
||||
'shareImage',
|
||||
<String, dynamic>{
|
||||
@ -118,12 +127,18 @@ class MethodChannelWeiboKit extends WeiboKitPlatform {
|
||||
bool clientOnly = false,
|
||||
}) {
|
||||
assert(text == null || text.length <= 1024);
|
||||
assert(imageUris.isNotEmpty && imageUris.every((Uri element) => element.isScheme('file')) && imageUris.map((Uri element) => File.fromUri(element).lengthSync()).reduce((int value, int element) => value + element) <= 30 * 1024 * 1024);
|
||||
assert(imageUris.isNotEmpty &&
|
||||
imageUris.every((Uri element) => element.isScheme('file')) &&
|
||||
imageUris
|
||||
.map((Uri element) => File.fromUri(element).lengthSync())
|
||||
.reduce((int value, int element) => value + element) <=
|
||||
30 * 1024 * 1024);
|
||||
return methodChannel.invokeMethod<void>(
|
||||
'shareMultiImage',
|
||||
<String, dynamic>{
|
||||
if (text != null && text.isNotEmpty) 'text': text,
|
||||
'imageUris': imageUris.map((Uri element) => element.toString()).toList(),
|
||||
'imageUris':
|
||||
imageUris.map((Uri element) => element.toString()).toList(),
|
||||
'clientOnly': clientOnly,
|
||||
},
|
||||
);
|
||||
@ -136,7 +151,8 @@ class MethodChannelWeiboKit extends WeiboKitPlatform {
|
||||
bool clientOnly = false,
|
||||
}) {
|
||||
assert(text == null || text.length <= 1024);
|
||||
assert(videoUri.isScheme('file') && File.fromUri(videoUri).lengthSync() <= 50 * 1024 * 1024);
|
||||
assert(videoUri.isScheme('file') &&
|
||||
File.fromUri(videoUri).lengthSync() <= 50 * 1024 * 1024);
|
||||
return methodChannel.invokeMethod<void>(
|
||||
'shareVideo',
|
||||
<String, dynamic>{
|
||||
|
@ -31,9 +31,11 @@ abstract class WeiboKitPlatform extends PlatformInterface {
|
||||
required String appKey,
|
||||
required String? universalLink,
|
||||
required List<String> scope,
|
||||
String redirectUrl = WeiboRegister.DEFAULT_REDIRECTURL, // 新浪微博开放平台 -> 我的应用 -> 应用信息 -> 高级信息 -> OAuth2.0授权设置
|
||||
String redirectUrl = WeiboRegister
|
||||
.DEFAULT_REDIRECTURL, // 新浪微博开放平台 -> 我的应用 -> 应用信息 -> 高级信息 -> OAuth2.0授权设置
|
||||
}) {
|
||||
throw UnimplementedError('registerApp({required appKey, required universalLink, required scope, redirectUrl}) has not been implemented.');
|
||||
throw UnimplementedError(
|
||||
'registerApp({required appKey, required universalLink, required scope, redirectUrl}) has not been implemented.');
|
||||
}
|
||||
|
||||
///
|
||||
@ -48,7 +50,8 @@ abstract class WeiboKitPlatform extends PlatformInterface {
|
||||
|
||||
///
|
||||
Future<bool> isSupportMultipleImage() {
|
||||
throw UnimplementedError('isSupportMultipleImage() has not been implemented.');
|
||||
throw UnimplementedError(
|
||||
'isSupportMultipleImage() has not been implemented.');
|
||||
}
|
||||
|
||||
/// 登录
|
||||
@ -57,7 +60,8 @@ abstract class WeiboKitPlatform extends PlatformInterface {
|
||||
required List<String> scope,
|
||||
String redirectUrl = WeiboRegister.DEFAULT_REDIRECTURL,
|
||||
}) {
|
||||
throw UnimplementedError('auth({required appKey, required scope, redirectUrl}) has not been implemented.');
|
||||
throw UnimplementedError(
|
||||
'auth({required appKey, required scope, redirectUrl}) has not been implemented.');
|
||||
}
|
||||
|
||||
/// 分享 - 文本
|
||||
@ -65,7 +69,8 @@ abstract class WeiboKitPlatform extends PlatformInterface {
|
||||
required String text,
|
||||
bool clientOnly = false /* Android Only */,
|
||||
}) {
|
||||
throw UnimplementedError('shareText({required text, clientOnly}) has not been implemented.');
|
||||
throw UnimplementedError(
|
||||
'shareText({required text, clientOnly}) has not been implemented.');
|
||||
}
|
||||
|
||||
/// 分享 - 图片
|
||||
@ -76,7 +81,8 @@ abstract class WeiboKitPlatform extends PlatformInterface {
|
||||
Uri? imageUri,
|
||||
bool clientOnly = false /* Android Only */,
|
||||
}) {
|
||||
throw UnimplementedError('shareImage({text, imageData, imageUri, clientOnly}) has not been implemented.');
|
||||
throw UnimplementedError(
|
||||
'shareImage({text, imageData, imageUri, clientOnly}) has not been implemented.');
|
||||
}
|
||||
|
||||
/// 分享 - 多图
|
||||
@ -85,7 +91,8 @@ abstract class WeiboKitPlatform extends PlatformInterface {
|
||||
required List<Uri> imageUris,
|
||||
bool clientOnly = false /* Android Only */,
|
||||
}) {
|
||||
throw UnimplementedError('shareMultiImage({text, required imageUris, clientOnly}) has not been implemented.');
|
||||
throw UnimplementedError(
|
||||
'shareMultiImage({text, required imageUris, clientOnly}) has not been implemented.');
|
||||
}
|
||||
|
||||
/// 分享 - 视频
|
||||
@ -94,7 +101,8 @@ abstract class WeiboKitPlatform extends PlatformInterface {
|
||||
required Uri videoUri,
|
||||
bool clientOnly = false /* Android Only */,
|
||||
}) {
|
||||
throw UnimplementedError('shareVideo({text, required videoUri, clientOnly}) has not been implemented.');
|
||||
throw UnimplementedError(
|
||||
'shareVideo({text, required videoUri, clientOnly}) has not been implemented.');
|
||||
}
|
||||
|
||||
/// 分享 - 网页
|
||||
@ -105,6 +113,7 @@ abstract class WeiboKitPlatform extends PlatformInterface {
|
||||
required String webpageUrl,
|
||||
bool clientOnly = false /* Android Only */,
|
||||
}) {
|
||||
throw UnimplementedError('shareWebpage({required title, required description, required thumbData, required webpageUrl, clientOnly}) has not been implemented.');
|
||||
throw UnimplementedError(
|
||||
'shareWebpage({required title, required description, required thumbData, required webpageUrl, clientOnly}) has not been implemented.');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user