From 7742eefd28c93f4d587c1261248da663bb79c33f Mon Sep 17 00:00:00 2001 From: v7lin Date: Tue, 26 Jul 2022 11:30:19 +0800 Subject: [PATCH] format --- example/lib/main.dart | 31 +++++++++++++------ lib/src/weibo_kit_method_channel.dart | 34 +++++++++++++++------ lib/src/weibo_kit_platform_interface.dart | 37 ++++++++++++++--------- 3 files changed, 69 insertions(+), 33 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index bd7823e..ad1c230 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -95,7 +95,8 @@ class _HomeState extends State { 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 { 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 { 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 { 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', diff --git a/lib/src/weibo_kit_method_channel.dart b/lib/src/weibo_kit_method_channel.dart index e8716ef..4593c93 100644 --- a/lib/src/weibo_kit_method_channel.dart +++ b/lib/src/weibo_kit_method_channel.dart @@ -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 _respStreamController = StreamController.broadcast(); + late final MethodChannel methodChannel = + const MethodChannel('v7lin.github.io/weibo_kit') + ..setMethodCallHandler(_handleMethod); + final StreamController _respStreamController = + StreamController.broadcast(); Future _handleMethod(MethodCall call) async { switch (call.method) { case 'onAuthResp': - _respStreamController.add(AuthResp.fromJson((call.arguments as Map).cast())); + _respStreamController.add(AuthResp.fromJson( + (call.arguments as Map).cast())); break; case 'onShareMsgResp': - _respStreamController.add(ShareMsgResp.fromJson((call.arguments as Map).cast())); + _respStreamController.add(ShareMsgResp.fromJson( + (call.arguments as Map).cast())); break; } } @@ -57,7 +62,8 @@ class MethodChannelWeiboKit extends WeiboKitPlatform { @override Future isSupportMultipleImage() async { - return await methodChannel.invokeMethod('isSupportMultipleImage') ?? false; + return await methodChannel.invokeMethod('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( 'shareImage', { @@ -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( 'shareMultiImage', { 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( 'shareVideo', { diff --git a/lib/src/weibo_kit_platform_interface.dart b/lib/src/weibo_kit_platform_interface.dart index 1c68442..05f5cd2 100644 --- a/lib/src/weibo_kit_platform_interface.dart +++ b/lib/src/weibo_kit_platform_interface.dart @@ -31,9 +31,11 @@ abstract class WeiboKitPlatform extends PlatformInterface { required String appKey, required String? universalLink, required List 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 isSupportMultipleImage() { - throw UnimplementedError('isSupportMultipleImage() has not been implemented.'); + throw UnimplementedError( + 'isSupportMultipleImage() has not been implemented.'); } /// 登录 @@ -57,15 +60,17 @@ abstract class WeiboKitPlatform extends PlatformInterface { required List 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.'); } /// 分享 - 文本 Future shareText({ required String text, - bool clientOnly = false/* Android Only */, + 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.'); } /// 分享 - 图片 @@ -74,27 +79,30 @@ abstract class WeiboKitPlatform extends PlatformInterface { String? text, Uint8List? imageData, Uri? imageUri, - bool clientOnly = false/* Android Only */, + 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.'); } /// 分享 - 多图 Future shareMultiImage({ String? text, required List imageUris, - bool clientOnly = false/* Android Only */, + 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.'); } /// 分享 - 视频 Future shareVideo({ String? text, required Uri videoUri, - bool clientOnly = false/* Android Only */, + 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.'); } /// 分享 - 网页 @@ -103,8 +111,9 @@ abstract class WeiboKitPlatform extends PlatformInterface { required String description, required Uint8List thumbData, required String webpageUrl, - bool clientOnly = false/* Android Only */, + 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.'); } }