57 lines
1.7 KiB
Dart
57 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:raid_manager/api/request.dart';
|
|
import 'package:raid_manager/raid_info_page.dart';
|
|
import 'package:raid_manager/types/md_raid_system.dart';
|
|
|
|
class RaidPage extends StatefulWidget {
|
|
const RaidPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<RaidPage> createState() => _RaidPageState();
|
|
}
|
|
|
|
class _RaidPageState extends State<RaidPage> {
|
|
Future<MdRaidSystem> fetchRaids() async {
|
|
return MdRaidSystem.fromJson(await getJson('/api/raiddevices'));
|
|
}
|
|
|
|
late final myFetch = fetchRaids();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder(
|
|
future: myFetch,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData) {
|
|
final data = snapshot.data!;
|
|
return ListView.builder(
|
|
itemCount: data.raids.length,
|
|
itemBuilder: (context, idx) {
|
|
return ListTile(
|
|
title: Text(
|
|
data.raids[idx].name,
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
|
),
|
|
subtitle: Text(
|
|
"${data.raids[idx].level} - ${data.raids[idx].faulty ? "errored" : "active sync"}",
|
|
style: Theme.of(context).textTheme.labelMedium,
|
|
),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => RaidInfoPage(raid: data.raids[idx])));
|
|
},
|
|
);
|
|
},
|
|
);
|
|
} else if (snapshot.hasError) {
|
|
return const Text("errored");
|
|
} else {
|
|
return const Text("loading...");
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|