import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:raid_manager/api/request.dart'; import 'package:raid_manager/breadcrumb_page.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 createState() => _DiskPageState(); } class _DiskPageState extends State { Future> fetchDisks() async { return ((await getJson('/api/disks')) as List) .map((e) => Disk.fromJson(e)) .toList(growable: false); } @override void initState() { super.initState(); myFetch = fetchDisks(); } late Future> 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(context, listen: false) .pushPage( const Text("Mysupercool page"), data[idx].name); }, ); }, ); } else { return const Text("loading..."); } }, ), ); } @override Widget build(BuildContext context) { return BreadCrumbPage( mainPage: _buildMainPage(), rootName: "Disks", ); } }