I'm trying to place a container before the contents of a listview but some how the container isn't rendered when i run the app. My code
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http ;
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
String url="https://randomuser.me/api/?results=10";
Future<List<dynamic>> fetchPlayers() async{
final result = await http.get(Uri.parse(url));
return json.decode(result.body)['results'];
}
String name(dynamic player){
return player['name']['first'] + " " + player['name']
['last'];
}
String position(dynamic player){
return player['name']['last'];
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
margin: const EdgeInsets.fromLTRB(35, 45, 30, 20),
child:
FutureBuilder<List<dynamic>>(
future: fetchPlayers(),
builder: (BuildContext context, AsyncSnapshot
snapshot) {
if (snapshot.hasData) {
return Column(
children: [
Container(
child: Text("I want a container here"),
),
ListView.builder(
padding: EdgeInsets.all(8),
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int
index){
return
Card(
child: Column(
children: <Widget>[
ListTile(
leading: CircleAvatar(
radius: 30, backgroundImage:
NetworkImage(
snapshot.data[index]
['picture']['large'])),
title:
Text(name(snapshot.data[index])),
subtitle:
Text(position(snapshot.data[index])),
)
],
),
);
})
]
);
}
else{
return Center(child:
CircularProgressIndicator());
}
},
),)
);
}
The contents of a container are not seen when i run my app.I'm not really familiar with flutter i guess i'm doing something wrong. Could someone help please
UPDATE :
I wanted my container to be displayed after the data has been loaded.After following an approach shown below ,now the container is seen but the data of the ListView are not.
