ListView construction properly done

This commit is contained in:
2023-12-26 21:08:23 +02:00
parent 09a8774423
commit e9b9e49509

View File

@@ -23,31 +23,34 @@ class _FetchAPIState extends State<FetchAPI> {
appBar: AppBar(
title: const Text("Fetching API"),
),
body: ListView(
children: [
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(snapshot.data![index].timeOfDay),
body: Row(
children: <Widget>[
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(snapshot.data![index].timeOfDay),
);
},
);
},
);
}
},
}
},
),
),
),
InkWell(
onTap: () {
Navigator.pushNamedAndRemoveUntil(
context, '/', (route) => false);
Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false);
},
child: Container(
padding: const EdgeInsets.all(20.0),
@@ -58,4 +61,10 @@ class _FetchAPIState extends State<FetchAPI> {
),
);
}
@override
void initState() {
super.initState();
fetchedArrivals = fetchArrivals();
}
}