aliyun_oss_android 0.0.4+9
aliyun_oss_android: ^0.0.4+9 copied to clipboard
android implementation of the aliyun_oss_plugin.
import 'package:aliyun_oss_platform_interface/aliyun_oss_platform_interface.dart';
import 'package:flutter/material.dart';
import 'dart:async';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
dynamic initResult;
double? progress;
bool? finish;
String? error;
@override
void initState() {
super.initState();
initOSS();
AliyunOSSPlatform.instance.addUploadMethodCallListener(UploadMethodCallListener(
initListener: (initData) {},
progressListener: (progressData) {
progress = progressData.totalBytesSent /
progressData.totalBytesExpectedToSend;
setState(() {});
},
failListener: (failData) {
error = failData.error;
setState(() {});
}));
}
initOSS() async {
initResult = await AliyunOSSPlatform.instance.init(
stsEndpoint,
OSSStsTokenCredentialProvider(
accessKeyId: stsAccessKeyId,
secretKeyId: stsAccessKeySecret,
securityToken: stsSecurityToken),
// OSSPlainTextAKSKCredentialProvider(
// accessKeyId: accessKeyId,
// accessKeySecret: accessKeySecret,
// ),
);
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text(error != null
? "上传错误: $error"
: 'init Result: $initResult, progress: $progress, finish: $finish'),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
// runPlayground();
// AliyunOSSPlatform.instance.upload(bucketName);
initOSS();
},
child: const Icon(Icons.send),
),
),
);
}
}