Flutter Dio GET :
Virtually each and every app has a capability, community calls are applied from time to time to make the paintings finished. However right here the purpose is how briskly does the community name works.
On this a part of the academic we will be able to be seeing throughout the implementation of the quickest approach to fetch the information to your flutter app the use of Dio library.
pubspec.yaml :
We wish to upload the newest model of dio library and ensure it’s sync correctly with flutter model.
dependencies: flutter: sdk: flutter dio: ^4.0.6
major.dart :
We can create a technique for fetching knowledge and will likely be using it in our code.
void fetchData() async{ var dio = Dio(); var reaction = look forward to dio.get("https://jsonplaceholder.typicode.com/posts"); print(reaction.statusCode); print(reaction.knowledge.toString()); }
Offering the whole code for flutter dio library implementation.
import 'package deal:dio/dio.dart'; import 'package deal:flutter/subject material.dart'; void major(){ runApp(const MyApp()); } magnificence MyApp extends StatelessWidget { const MyApp({Key? key}) : tremendous(key: key); @override Widget construct(BuildContext context) { go back MaterialApp( house: Scaffold( frame: Heart( kid: Column( mainAxisAlignment: MainAxisAlignment.middle, youngsters: [ TextButton(onPressed: (){ fetchData(); }, child: const Text("Post Data")) ], ), ), ), ); } } void fetchData() async{ var dio = Dio(); var reaction = look forward to dio.get("https://jsonplaceholder.typicode.com/posts"); print(reaction.statusCode); print(reaction.knowledge.toString()); }