Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter how to get data from api without future builder

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading