Raid_Manager/app/lib/disk_page.dart

54 lines
1.5 KiB
Dart
Raw Normal View History

2022-12-06 23:19:10 +00:00
import 'package:flutter/material.dart';
import 'package:raid_manager/api/request.dart';
import 'package:raid_manager/types/disk.dart';
import 'package:raid_manager/utils/file_formatter.dart';
class DiskPage extends StatefulWidget {
const DiskPage({Key? key}) : super(key: key);
@override
State<DiskPage> createState() => _DiskPageState();
}
class _DiskPageState extends State<DiskPage> {
Future<List<Disk>> fetchDisks() async {
return (await getJson('/api/disks') as List)
.map((e) => Disk.fromJson(e))
.toList(growable: false);
}
late final myFetch = fetchDisks();
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: myFetch,
builder: (context, snapshot) {
if (snapshot.hasData) {
final data = snapshot.data!;
return ListView.builder(
itemCount: data.length,
itemBuilder: (context, idx) {
return ListTile(
title: Text(
data[idx].name,
style: Theme.of(context).textTheme.headlineMedium,
),
subtitle: Text(
data[idx].size.readableFileSize(),
style: Theme.of(context).textTheme.labelMedium,
),
onTap: () {},
);
},
);
} else if (snapshot.hasError) {
return const Text("errored");
} else {
return const Text("loading...");
}
},
);
}
}