mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-16 13:23:41 +00:00
feat: create task with advanced options (#157)
This commit is contained in:
22 files changed
+357
-136
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -12,7 +13,9 @@ class Util {
|
||||
}
|
||||
|
||||
static String fmtByte(int byte) {
|
||||
if (byte < 1024) {
|
||||
if (byte < 0) {
|
||||
return "0 B";
|
||||
} else if (byte < 1024) {
|
||||
return "$byte B";
|
||||
} else if (byte < 1024 * 1024) {
|
||||
return "${(byte / 1024).toStringAsFixed(2)} KB";
|
||||
@@ -61,6 +64,14 @@ class Util {
|
||||
return kIsWeb;
|
||||
}
|
||||
|
||||
static List<String> textToLines(String text) {
|
||||
if (text.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
const ls = LineSplitter();
|
||||
return ls.convert(text);
|
||||
}
|
||||
|
||||
// if one future complete, return the result, only all future error, return the last error
|
||||
static anyOk<T>(Iterable<Future<T>> futures) {
|
||||
final completer = Completer<T>();
|
||||
@@ -74,9 +85,7 @@ class Util {
|
||||
}).catchError((e) {
|
||||
lastError = e;
|
||||
count--;
|
||||
print(count);
|
||||
if (count == 0) {
|
||||
print("completeError");
|
||||
completer.completeError(lastError);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user