Pull down to refresh (yw lingy)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user