Raid_Manager/app/lib/raid_page.dart

57 lines
1.7 KiB
Dart
Raw Normal View History

2022-12-06 21:29:48 +00:00
import 'package:flutter/material.dart';
2022-12-06 23:19:10 +00:00
import 'package:raid_manager/api/request.dart';
2022-12-06 21:29:48 +00:00
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 {
2022-12-06 23:19:10 +00:00
return MdRaidSystem.fromJson(await getJson('/api/raiddevices'));
2022-12-06 21:29:48 +00:00
}
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...");
}
},
);
}
}