I tried to get data from api like this, but I couldn’t display it
I need to get data from request api and show it in widget, api gives me data of one user, i want to show my data like this :
getUser() async {
var response = await http.get(Uri.parse(url));
var jsonData = jsonDecode(response.body);
return jsonData['data'].map<User>(User.fromJson).toString();
}
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(12))),
padding: EdgeInsets.only(left: 10, right: 10),
height: 120,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CircleAvatar(
radius: 28,
backgroundImage: NetworkImage('API AVATAR'),
),
Text(
'TEXT FROM MY API',
style: TextStyle(fontSize: 17, color: Colors.black),
),
Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
),
],
),
), ```
>Solution :
As a ShortCut Call Get Data Function In a SetState of Init Method, or Build
But a Proper Way would be to Use Provider Package and Listen for Data In the Builder,By Implementing Change Notifier Class