|
@@ -6,14 +6,12 @@ import 'package:flutter/services.dart';
|
|
typedef onData = void Function(dynamic event);
|
|
typedef onData = void Function(dynamic event);
|
|
|
|
|
|
class SyFlutterQiniuStorage {
|
|
class SyFlutterQiniuStorage {
|
|
- static const MethodChannel _channel =
|
|
|
|
- const MethodChannel('sy_flutter_qiniu_storage');
|
|
|
|
- static const EventChannel _eventChannel =
|
|
|
|
- const EventChannel('sy_flutter_qiniu_storage_event');
|
|
|
|
|
|
+ static const MethodChannel _channel = const MethodChannel('sy_flutter_qiniu_storage');
|
|
|
|
+ static const EventChannel _eventChannel = const EventChannel('sy_flutter_qiniu_storage_event');
|
|
|
|
|
|
- Stream _onChanged;
|
|
|
|
|
|
+ Stream? _onChanged;
|
|
|
|
|
|
- Stream onChanged() {
|
|
|
|
|
|
+ Stream? onChanged() {
|
|
if (_onChanged == null) {
|
|
if (_onChanged == null) {
|
|
_onChanged = _eventChannel.receiveBroadcastStream();
|
|
_onChanged = _eventChannel.receiveBroadcastStream();
|
|
}
|
|
}
|
|
@@ -24,8 +22,7 @@ class SyFlutterQiniuStorage {
|
|
///
|
|
///
|
|
/// key 保存到七牛的文件名
|
|
/// key 保存到七牛的文件名
|
|
Future<UploadResult> upload(String filepath, String token, String key) async {
|
|
Future<UploadResult> upload(String filepath, String token, String key) async {
|
|
- var res = await _channel.invokeMethod('upload',
|
|
|
|
- <String, String>{"filepath": filepath, "token": token, "key": key});
|
|
|
|
|
|
+ var res = await _channel.invokeMethod('upload', <String, String>{"filepath": filepath, "token": token, "key": key});
|
|
|
|
|
|
return UploadResult.fromJson(json.decode(res));
|
|
return UploadResult.fromJson(json.decode(res));
|
|
}
|
|
}
|
|
@@ -39,17 +36,17 @@ class SyFlutterQiniuStorage {
|
|
//上传结果
|
|
//上传结果
|
|
class UploadResult {
|
|
class UploadResult {
|
|
//是否成功
|
|
//是否成功
|
|
- bool success;
|
|
|
|
|
|
+ late final bool success;
|
|
|
|
|
|
//错误信息
|
|
//错误信息
|
|
- String error;
|
|
|
|
|
|
+ String? error;
|
|
|
|
|
|
//客户端指定的key
|
|
//客户端指定的key
|
|
- String key;
|
|
|
|
|
|
+ String? key;
|
|
|
|
|
|
//上传成功后,自定义七牛云最终返回給上传端的数据
|
|
//上传成功后,自定义七牛云最终返回給上传端的数据
|
|
//七牛上传策略 https://developer.qiniu.com/kodo/manual/1206/put-policy
|
|
//七牛上传策略 https://developer.qiniu.com/kodo/manual/1206/put-policy
|
|
- Map<String, dynamic> result;
|
|
|
|
|
|
+ Map<String, dynamic>? result;
|
|
|
|
|
|
UploadResult.fromJson(Map<String, dynamic> json) {
|
|
UploadResult.fromJson(Map<String, dynamic> json) {
|
|
success = json['success'] ?? false;
|
|
success = json['success'] ?? false;
|