2022-12-06 23:19:10 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-12-09 00:45:00 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2022-12-06 23:19:10 +00:00
|
|
|
import 'package:raid_manager/api/request.dart';
|
2022-12-09 11:50:58 +00:00
|
|
|
import 'package:raid_manager/breadcrumb_page/breadcrumb_page.dart';
|
2022-12-06 23:19:10 +00:00
|
|
|
import 'package:raid_manager/types/disk.dart';
|
2022-12-09 11:50:58 +00:00
|
|
|
import 'package:raid_manager/utils/disk_info_page.dart';
|
2022-12-06 23:19:10 +00:00
|
|
|
import 'package:raid_manager/utils/file_formatter.dart';
|
|
|
|
|
2022-12-09 14:44:27 +00:00
|
|
|
import 'breadcrumb_page/breadcrumb_controller.dart';
|
2022-12-09 11:50:58 +00:00
|
|
|
|
2022-12-06 23:19:10 +00:00
|
|
|
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 {
|
2022-12-09 00:45:00 +00:00
|
|
|
return ((await getJson('/api/disks')) as List)
|
2022-12-06 23:19:10 +00:00
|
|
|
.map((e) => Disk.fromJson(e))
|
|
|
|
.toList(growable: false);
|
|
|
|
}
|
|
|
|
|
2022-12-09 00:45:00 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
myFetch = fetchDisks();
|
|
|
|
}
|
|
|
|
|
|
|
|
late Future<List<Disk>> myFetch;
|
|
|
|
|
|
|
|
Widget _buildMainPage() {
|
|
|
|
return Expanded(
|
|
|
|
child: FutureBuilder(
|
|
|
|
future: myFetch,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.connectionState != ConnectionState.done) {
|
|
|
|
return const CircularProgressIndicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
print(snapshot.error);
|
|
|
|
return const Text("errored");
|
|
|
|
} else if (snapshot.hasData) {
|
|
|
|
final data = snapshot.data!;
|
|
|
|
return ListView.builder(
|
|
|
|
itemCount: data.length,
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
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: () {
|
|
|
|
Provider.of<BreadCrumbController>(context, listen: false)
|
2022-12-09 11:50:58 +00:00
|
|
|
.pushPage(const DiskInfoPage(), data[idx].name);
|
2022-12-09 00:45:00 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Text("loading...");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-12-06 23:19:10 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-12-09 00:45:00 +00:00
|
|
|
return BreadCrumbPage(
|
|
|
|
mainPage: _buildMainPage(),
|
|
|
|
rootName: "Disks",
|
2022-12-06 23:19:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|