Pull down to refresh (yw lingy)

This commit is contained in:
2023-12-27 16:55:37 +02:00
parent c9f990e7fd
commit cecc3a93a8

View File

@@ -24,53 +24,64 @@ class _FetchAPIState extends State<FetchAPI> {
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<List<Arrival>>(
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<List<Arrival>>(
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<void> _refreshData() async {
setState(() {
fetchedArrivals = fetchArrivals();
});
}
@override
void initState() {
super.initState();
@@ -97,4 +108,4 @@ String weekNumToString(int weekday) {
}
throw "AAAAAAAAA";
}
}