JamesZhang 1 ano atrás
pai
commit
adf17b09b0

+ 54 - 0
lib/components/imageButton.dart

@@ -0,0 +1,54 @@
+
+import 'package:flutter/material.dart';
+
+
+class ImageButton extends StatelessWidget {
+  final Size buttonSize;
+  final String image;
+  final Size imageSize;
+  final Color bgColor;
+  final double borderRadius;
+  final Color borderColor;
+  final double borderWidth;
+  final VoidCallback onTap;
+
+  ImageButton({
+    required Size buttonSize,
+    required this.image,
+    Size? imageSize,
+    Color bgColor = Colors.white,
+    this.borderRadius = 5,
+    Color? borderColor,
+    this.borderWidth = 1,
+    required this.onTap,
+  })
+    : buttonSize = buttonSize,
+      imageSize = imageSize ?? buttonSize,
+      bgColor = bgColor,
+      borderColor = borderColor ?? bgColor
+  ;
+
+  @override
+  Widget build(BuildContext context) {
+    return GestureDetector(
+      onTap: onTap,
+      child: Container(
+        width: buttonSize.width,
+        height: buttonSize.height,
+        decoration: BoxDecoration(
+          color: bgColor,
+          shape: BoxShape.rectangle,
+          borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
+          border: Border.all(color: borderColor),
+        ),
+        child: Center(
+          child: Image.asset(
+            image,
+            width: imageSize.width,
+            height: imageSize.height,
+          ),
+        ),
+      ),
+    );
+  }
+}

+ 2 - 0
lib/components/index.dart

@@ -0,0 +1,2 @@
+
+export 'imageButton.dart';

+ 6 - 0
lib/util/fileUtils.dart

@@ -30,6 +30,12 @@ bool isFile(path) {
   return FileSystemEntity.isFileSync(path);
 }
 
+Future<int> fileSizeOf(path) async {
+  final file = File(path);
+  final size = await file.length();
+  return size;
+}
+
 
 
 createFolder(String folderPath) async {

+ 5 - 5
lib/util/riverpodUtils.dart

@@ -2,15 +2,15 @@
 import 'package:flutter_riverpod/flutter_riverpod.dart';
 
 
-class RiverpodStateWatch {
-  final dynamic value;
-  final StateController<dynamic> notifier;
+class RiverpodStateWatch<T> {
+  final T value;
+  final StateController<T> notifier;
 
-  RiverpodStateWatch(WidgetRef ref, StateProvider provider):
+  RiverpodStateWatch(WidgetRef ref, StateProvider<T> provider):
         value = ref.watch(provider),
         notifier = ref.watch(provider.notifier);
 
-  void setState(dynamic value) {
+  void setState(T value) {
     notifier.state = value;
   }
 }

+ 38 - 0
lib/util/tools.dart

@@ -74,3 +74,41 @@ String formatFileSize(int size) {
   }
   return '${fileSizeInTB.toStringAsFixed(2)} TB';
 }
+
+
+// 均匀分组
+List<int> uniformGrouping(int totalSize, int defaultGroupSize) {
+  if (totalSize < 0) {
+    return [];
+  } else if (totalSize == 0) {
+    return [0];
+  }
+
+  final int theUpperLimit = (defaultGroupSize * 1.5).toInt(); // 折行上限
+  if (totalSize <= theUpperLimit) {
+    return [totalSize];
+  } else if ((totalSize > theUpperLimit) && (totalSize <= (defaultGroupSize * 2))) {
+    int half = totalSize ~/ 2;
+    return [half, totalSize - half];
+  }
+
+  final int groupNumber = totalSize ~/ defaultGroupSize;
+  final int remainder = totalSize % defaultGroupSize;
+  List<int> group = [];
+  if (remainder == 0) {
+    for (int i = 0; i < groupNumber; i++) {
+      group.add(defaultGroupSize);
+    }
+  } else {
+    final splitRemainder = remainder ~/ groupNumber;
+    final groupRemainder = remainder % groupNumber;
+    for (int i = 0; i < groupRemainder; i++) {
+      group.add(defaultGroupSize + splitRemainder + 1);
+    }
+    for (int i = groupRemainder; i < groupNumber; i++) {
+      group.add((defaultGroupSize + splitRemainder));
+    }
+  }
+
+  return group;
+}

+ 4 - 4
pubspec.lock

@@ -463,18 +463,18 @@ packages:
     dependency: transitive
     description:
       name: material_color_utilities
-      sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
+      sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
       url: "https://pub.dev"
     source: hosted
-    version: "0.8.0"
+    version: "0.11.1"
   meta:
     dependency: transitive
     description:
       name: meta
-      sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
+      sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
       url: "https://pub.dev"
     source: hosted
-    version: "1.12.0"
+    version: "1.15.0"
   mime:
     dependency: transitive
     description: