-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload_notifier.dart
More file actions
57 lines (46 loc) · 1.27 KB
/
upload_notifier.dart
File metadata and controls
57 lines (46 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import 'dart:async';
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
class UploadNotifier extends ChangeNotifier {
final List<UploadItem> _uploadList = [];
final List<UploadItem> _uploadHistoryList = [];
UploadNotifier();
void addItem(UploadItem item) {
_uploadList.add(item);
notifyListeners();
}
void addItems(List<UploadItem> item) {
_uploadList.addAll(item);
notifyListeners();
}
void itemUploadCompleted(UploadItem item, {bool error = false}) {
_uploadList.remove(item);
item.error = error;
_uploadHistoryList.insert(0, item);
notifyListeners();
}
void removeItem(UploadItem item) {
_uploadList.remove(item);
notifyListeners();
}
void clearHistory() {
_uploadHistoryList.clear();
}
List<UploadItem> get uploadList => _uploadList;
List<UploadItem> get uploadHistoryList => _uploadHistoryList;
}
class UploadItem {
final File file;
final StreamController<double> progress;
final int albumId;
final CancelToken cancelToken;
bool error;
UploadItem({
required this.file,
required this.albumId,
this.error = false,
CancelToken? cancelToken,
}) : progress = StreamController<double>.broadcast(),
cancelToken = cancelToken ?? CancelToken();
}