feat: create task with advanced options (#157)

This commit is contained in:
Levi authored and GitHub committed 2023-07-19 22:52:51 +08:00
1 parent eb79dd5ac5
commit 7376e85895
22 files changed
+357 -136

No files matched your search

+12 -3
View File
@@ -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);
}
});