Files
pipelines/app/lib/features/settings/health/health_storage.dart
T

58 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'health_models.dart';
import 'health_widgets.dart';
class HealthStorage extends StatelessWidget {
const HealthStorage({super.key, this.value});
final Object? value;
@override
Widget build(BuildContext context) {
final value = this.value;
if (value is Map) {
final error = value['error'];
if (error is String && error.isNotEmpty) {
return HealthCard(title: 'Storage', child: Text(error));
}
}
final values = value is List ? value : const <dynamic>[];
return HealthCard(
title: 'Storage',
child: Column(
children: [
for (final raw in values.whereType<Map>())
Builder(
builder: (context) {
final row = healthMap(raw);
if (row['error'] case final String error
when error.isNotEmpty) {
return HealthRows([(healthText(row['mount']), error)]);
}
final total = row['total_bytes'] is num
? (row['total_bytes'] as num).toDouble()
: 0;
final used = row['used_bytes'];
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'${healthText(row['mount'])} · ${healthBytes(row['free_bytes'])} free of ${healthBytes(row['total_bytes'])}',
),
HealthMeter(
label: 'Used',
value:
healthRatio(row['used_percent']) ??
healthUsageRatio(used, total),
),
],
),
);
},
),
],
),
);
}
}