|
|
@@ -24,8 +24,10 @@ class UploadStatus {
|
|
|
|
|
|
class _UploadPageState extends State<UploadPage> with WidgetsBindingObserver {
|
|
|
late UploadService _uploadService;
|
|
|
- int _totalOperations = 0;
|
|
|
- int _uploadedOperations = 0;
|
|
|
+ int _totalCount = 0;
|
|
|
+ int _uploadedCount = 0;
|
|
|
+ int _errorCount = 0;
|
|
|
+ String _error = "";
|
|
|
int _status = UploadStatus.preparing; // 改为int类型
|
|
|
bool _isUploading = false;
|
|
|
bool _uploadCompleted = false;
|
|
|
@@ -71,7 +73,7 @@ class _UploadPageState extends State<UploadPage> with WidgetsBindingObserver {
|
|
|
case UploadStatus.completed:
|
|
|
return '上传完成';
|
|
|
case UploadStatus.error:
|
|
|
- return '上传出错,请稍后再试';
|
|
|
+ return '上传出错,请稍后再试($_error)';
|
|
|
case UploadStatus.exception:
|
|
|
return '上传异常,请稍后再试';
|
|
|
default:
|
|
|
@@ -130,8 +132,8 @@ class _UploadPageState extends State<UploadPage> with WidgetsBindingObserver {
|
|
|
setState(() {
|
|
|
_isUploading = true;
|
|
|
_status = UploadStatus.uploading; // 使用状态常量
|
|
|
- _uploadedOperations = 0;
|
|
|
- _totalOperations = 0;
|
|
|
+ _uploadedCount = 0;
|
|
|
+ _totalCount = 0;
|
|
|
_uploadCompleted = false;
|
|
|
});
|
|
|
}
|
|
|
@@ -140,11 +142,12 @@ class _UploadPageState extends State<UploadPage> with WidgetsBindingObserver {
|
|
|
logger.d('开始上传,$t');
|
|
|
// 注册回调
|
|
|
_uploadService.registerCallbacks(
|
|
|
- onProgress: (uploaded, total, status) {
|
|
|
+ onProgress: (uploaded, error, total, status) {
|
|
|
if (mounted) {
|
|
|
setState(() {
|
|
|
- _uploadedOperations = uploaded;
|
|
|
- _totalOperations = total;
|
|
|
+ _uploadedCount = uploaded;
|
|
|
+ _totalCount = total;
|
|
|
+ _errorCount = error;
|
|
|
});
|
|
|
}
|
|
|
logger.d('上传进度 $t:$uploaded/$total');
|
|
|
@@ -176,6 +179,7 @@ class _UploadPageState extends State<UploadPage> with WidgetsBindingObserver {
|
|
|
if (mounted) {
|
|
|
setState(() {
|
|
|
_isUploading = false;
|
|
|
+ _error = message;
|
|
|
_status = UploadStatus.error; // 使用状态常量
|
|
|
});
|
|
|
}
|
|
|
@@ -215,13 +219,15 @@ class _UploadPageState extends State<UploadPage> with WidgetsBindingObserver {
|
|
|
textAlign: TextAlign.center,
|
|
|
),
|
|
|
const SizedBox(height: 30),
|
|
|
- if (_totalOperations > 0) ...[
|
|
|
+ if (_totalCount > 0) ...[
|
|
|
LinearProgressIndicator(
|
|
|
- value: _uploadedOperations / _totalOperations,
|
|
|
+ value: _uploadedCount / _totalCount,
|
|
|
minHeight: 10,
|
|
|
),
|
|
|
const SizedBox(height: 10),
|
|
|
- Text('$_uploadedOperations / $_totalOperations'),
|
|
|
+ Text(
|
|
|
+ '$_uploadedCount / $_totalCount [$_errorCount 错误]',
|
|
|
+ ),
|
|
|
const SizedBox(height: 30),
|
|
|
],
|
|
|
if (_isUploading) ...[
|