Flutter dio Get & Post call implementation at once

Dhanisa Mashilfa

Flutter GET Write-up :

Flutter GET Put up the two the community phone calls are implemented concurrently utilizing dio library is discussed in this aspect of the tutorial.

Api calls are classified centered on the perform they do like making facts we make use of Put up, fetching the details we make use of GET, updating the data we make us of Put, deleting the data we use DELETE.

These are the few varieties i have specified you can locate substantially a lot more facts at https://www.amplifyabhi.com/2022/06/10/http-response-codes/

It could sound quite intriguing to execute both at the moment we have evidently stated this state of affairs via a video clip tutorial.

 

We have found the particular person implementation of flutter dio GET. And total enjoy listing of tutorial is presented in this article.

 

 

https://www.youtube.com/observe?v=o8aRL6-mIq0

 

pubspec.yaml:

Add dio library to your pubspec file. Present the newest model to avoid unwelcome mistakes.

dependencies:
  flutter:
    sdk: flutter
  dio: ^4..6

key.dart :

We will be executing equally GET and Article implementations for a presented api’s and will fetch the reaction at the moment working with array list.

Can fetch the data according to the positions.

Offer GET ask for

dio.get('https://jsonplaceholder.typicode.com/posts/1'),


Offer Article ask for

dio.post('https://jsonplaceholder.typicode.com/posts')

 

can fetch the information as

print(reaction[0].information)
print(reaction[1].details)

 

create a dio item and make api phone.

var dio = Dio()

 

You can locate the duration of the array as

response.duration

 

Offer a easy code to make a button click on so that api simply call can be started off.

Column(
  mainAxisAlignment: MainAxisAlignment.centre,
  youngsters: [
    TextButton(onPressed: ()
      fetchData();
    , child: const Text("Get / Post Data"))
  ],
),

 

 

void fetchData() async
  var dio = Dio()
  var response = await Foreseeable future.wait([
   
    dio.get('https://jsonplaceholder.typicode.com/posts/1'),
    dio.post('https://jsonplaceholder.typicode.com/posts')
  ])
  print(reaction.duration)
  print(response[0].knowledge)
  print(response[1].info)

 

 

Giving the total code for api implementation.

import 'package:dio/dio.dart'
import 'package:flutter/substance.dart'

void key()
  runApp(const MyApp())


class MyApp extends StatelessWidget 
  const MyApp(Essential? key) : tremendous(important: vital)

  @override
  Widget construct(BuildContext context) 
    return MaterialApp(
      property: Scaffold(
        human body: Centre(
          boy or girl: Column(
            mainAxisAlignment: MainAxisAlignment.middle,
            children: [
              TextButton(onPressed: ()
                fetchData();
              , child: const Text("Get / Post Data"))
            ],
          ),
        ),
      ),
    )
  


void fetchData() async
  var dio = Dio()
  var reaction = await Long term.wait around([
    
    dio.get('https://jsonplaceholder.typicode.com/posts/1'),
    dio.post('https://jsonplaceholder.typicode.com/posts')
  ])
  print(response.size)
  print(response[0].details)
  print(reaction[1].data)

 

If you have any query in this tutorial do allow us know in the remark section down below or go by means of the video tutorial for comprehensive output offered.

If you discovered this tutorial interesting share, like us for additional fascinating updates.

Next Post

U-Turn Audio Orbit Theory: A Turntable 10 Years In The Making

The very little engine that could tucked away in a suburb outdoors of Boston is practically 10 yrs previous and it is tricky not to be impressed by what Ben Carter and the folks at U-Convert Audio have attained. The new U-Change Audio Orbit Principle Turntable is a large milestone […]
U-Turn Audio Orbit Theory: A Turntable 10 Years In The Making