I want to fetch the data from API and display it in flutter app. I've been able to fetch the data using this methode :
@override
void initState() {
getprofile(widget.id);
super.initState();
}
Future<List<dynamic>> getprofile(int id) async {
var response = await Network().getData('/auth/user/$id');
var data = json.decode(response.body)['user'];
return data;
}
and i want to display it using ListView builder in this widget : how i can display the varaiable name in this case ?
Widget getBody() {
return Scaffold(
body: Container(
padding: EdgeInsets.only(left: 16, top: 1, right: 16),
child: FutureBuilder(
future: getprofile(widget.id),
builder: (BuildContext context,
AsyncSnapshot<List<dynamic>> snapshot) {
// String name = snapshot.data['name'];
if (snapshot != null) {
return ListView(
children: [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.white, Colors.white])),
child: Container(
width: double.infinity,
height: 350.0,
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 10.0,
),
Text(
"$name",
style: TextStyle(
fontSize: 22.0,
color: Colors.grey,
),
),
SizedBox(
height: 10.0,
),
