Files
app/lib/presentation/pages/profile/widgets/thick_storage_bar.dart
T
2026-05-15 09:03:09 +08:00

65 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
/// 粗进度条存储指示器
class ThickStorageBar extends StatelessWidget {
final int used;
final int total;
final double percentage;
const ThickStorageBar({
super.key,
required this.used,
required this.total,
required this.percentage,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(6),
child: LinearProgressIndicator(
value: total > 0 ? (used / total).clamp(0.0, 1.0) : 0,
minHeight: 10,
backgroundColor: colorScheme.primary.withValues(alpha: 0.12),
valueColor: AlwaysStoppedAnimation<Color>(colorScheme.primary),
borderRadius: BorderRadius.circular(6),
),
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'已使用 ${_formatBytes(used)}',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.hintColor,
),
),
Text(
'${_formatBytes(total)}',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.hintColor,
),
),
],
),
],
);
}
String _formatBytes(int bytes) {
if (bytes < 1024) return '$bytes B';
if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(1)} KB';
if (bytes < 1024 * 1024 * 1024) {
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
}
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(1)} GB';
}
}