Flutter Dio GET Community Name Implementation


Flutter Dio GET :

Nearly each app has a performance, community calls are utilized generally to make the work accomplished. However right here the purpose is how briskly does the community name works.

GET is the essential, most used API request we simply flick through any web site then the request made is GET.And once more primarily based on the duty we carry out within the web site api request may change type POST, PUT so on..

Community name implementation was an enormous activity to be carried out however this tutorial will simplify it to you as a way to carry out it in simply 1 min.

On this a part of the tutorial we shall be seeing by way of the implementation of the quickest approach to fetch the info in your flutter app utilizing Dio library.

You may undergo under tutorial for extra detailed updates on GET implementation and for extra API request refer dio playlist

 

 

pubspec.yaml :

We have to add the newest model of dio library and ensure it’s sync correctly with flutter model.

dependencies:
  flutter:
    sdk: flutter
  dio: ^4.0.6

 

most important.dart :

We are going to create a way for fetching information and shall be using it in our code.You can too attempt to implement concurrent community calls with each GET, POST.

We are able to fetch the standing code first in order that we are able to know the success of failure of the api name.Can discover extra particulars on standing codes right here.

 

void fetchData() async{
  var dio = Dio();
  var response = await dio.get("https://jsonplaceholder.typicode.com/posts");
  print(response.statusCode);
  print(response.information.toString());
}

 

Offering the complete code for flutter dio library implementation.

import 'bundle:dio/dio.dart';
import 'bundle:flutter/materials.dart';

void most important(){
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : tremendous(key: key);

  @override
  Widget construct(BuildContext context) {
    return MaterialApp(
      residence: Scaffold(
        physique: Heart(
          baby: Column(
            mainAxisAlignment: MainAxisAlignment.middle,
            youngsters: [
              TextButton(onPressed: (){
                fetchData();
              }, child: const Text("Post Data"))
            ],
          ),
        ),
      ),
    );
  }
}

void fetchData() async{
  var dio = Dio();
  var response = await dio.get("https://jsonplaceholder.typicode.com/posts");
  print(response.statusCode);
  print(response.information.toString());
}

 

If in case you have any question’s in flutter dio GET API request implementation do tell us within the remark part under.Should you like this tutorial do like and share us for extra attention-grabbing updates.

 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles