diff --git a/lib/fetcher.dart b/lib/fetcher.dart index 288367f..5d8d651 100644 --- a/lib/fetcher.dart +++ b/lib/fetcher.dart @@ -24,53 +24,64 @@ class _FetchAPIState extends State { fetchedArrivals = fetchArrivals(); }); }, - icon: const Icon(Icons.refresh_rounded)) + icon: const Icon(Icons.refresh_sharp), + ), + const SizedBox(width: 30,), ], ), - body: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - child: SizedBox( - child: FutureBuilder>( - future: fetchedArrivals, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const CircularProgressIndicator(); - } else if (snapshot.hasError) { - return Text('Failed to fetch data.\nError: ${snapshot.error}'); - } else { - return ListView.builder( - itemCount: snapshot.data!.length, - itemBuilder: (context, index) { - return ListTile( - title: Text("Arrival Time: ${snapshot.data![index].timeOfDay}"), - titleAlignment: ListTileTitleAlignment.center, - subtitle: Text("Week Day: ${weekNumToString(snapshot.data![index].weekDay)}"), - ); - }, - ); - } - }, + body: RefreshIndicator( + onRefresh: _refreshData, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + child: SizedBox( + child: FutureBuilder>( + future: fetchedArrivals, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const CircularProgressIndicator(); + } else if (snapshot.hasError) { + return Text('Failed to fetch data.\nError: ${snapshot.error}'); + } else { + return ListView.builder( + itemCount: snapshot.data!.length, + itemBuilder: (context, index) { + return ListTile( + title: Text("Arrival Time: ${snapshot.data![index].timeOfDay}"), + titleAlignment: ListTileTitleAlignment.center, + subtitle: Text("Week Day: ${weekNumToString(snapshot.data![index].weekDay)}"), + ); + }, + ); + } + }, + ), ), ), - ), - const SizedBox(height: 30,), - InkWell( - onTap: () { - Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false); - }, - child: Container( - padding: const EdgeInsets.all(20.0), - child: const Text("Homescreen"), + const SizedBox(height: 30,), + InkWell( + onTap: () { + Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false); + }, + child: Container( + padding: const EdgeInsets.all(20.0), + child: const Text("Homescreen"), + ), ), - ), - const SizedBox(height: 35,), - ], + const SizedBox(height: 35,), + ], + ), ), ); } + Future _refreshData() async { + setState(() { + fetchedArrivals = fetchArrivals(); + }); + } + @override void initState() { super.initState(); @@ -97,4 +108,4 @@ String weekNumToString(int weekday) { } throw "AAAAAAAAA"; -} \ No newline at end of file +}