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 createState() => _RaidPageState(); } class _RaidPageState extends State { Future 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!; if (data.raids.isEmpty) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.warning_amber_rounded, size: 42, color: Colors.white.withOpacity(.6)), const SizedBox( height: 7, ), Text("No Raid available", style: Theme.of(context).textTheme.headlineMedium) ], ); } else { 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..."); } }, ); } }