Flutter dio Get & Publish name implementation without delay


Flutter GET POST :

Flutter GET POST each the community calls are applied concurrently utilizing dio library is defined on this a part of the tutorial.

Api calls are labeled based mostly on the work they do like creating knowledge we make use of POST, fetching the info we make use of GET, updating the info we make us of PUT, deleting the info we use DELETE.

Now we have used GET and POST request right here you could strive some other api request as a observe.

These are the few sorts i’ve specified you will discover way more info at https://www.amplifyabhi.com/2022/06/10/http-response-codes/

It’d sound very attention-grabbing to execute each flutter get put up without delay we now have clearly defined this situation by a video tutorial.

 

Now we have seen the person implementation of flutter dio GET. And full play listing of instructional is supplied right here.

 

 

 

pubspec.yaml:

Add dio library to your pubspec file. Present the most recent model to keep away from undesirable errors.

dependencies:
  flutter:
    sdk: flutter
  dio: ^4.0.6

major.dart :

We can be executing each GET and POST implementations for a given api’s and can fetch the response without delay utilizing array listing.

Can fetch the info in accordance with the positions.

 

Present GET request

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


Present POST request

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

 

can fetch the info as right here 0 and 1 represents the situation of information contained in the array as we acquired our response saved in array.

print(response[0].knowledge);
print(response[1].knowledge);

 

create a dio object and make api name.

var dio = Dio();

 

You will discover the size of the array as

response.size

 

Present a easy code to make a button click on in order that api name might be began.

Column(
  mainAxisAlignment: MainAxisAlignment.heart,
  kids: [
    TextButton(onPressed: (){
      fetchData();
    }, child: const Text("Get / Post Data"))
  ],
),

 

 

void fetchData() async{
  var dio = Dio();
  var response = await Future.wait([
   
    dio.get('https://jsonplaceholder.typicode.com/posts/1'),
    dio.post('https://jsonplaceholder.typicode.com/posts')
  ]);
  print(response.size);
  print(response[0].knowledge);
  print(response[1].knowledge);
}

 

 

Offering the total code for flutter get put up api implementation.

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

void major(){
  runApp(const MyApp());
}

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

  @override
  Widget construct(BuildContext context) {
    return MaterialApp(
      dwelling: Scaffold(
        physique: Middle(
          little one: Column(
            mainAxisAlignment: MainAxisAlignment.heart,
            kids: [
              TextButton(onPressed: (){
                fetchData();
              }, child: const Text("Get / Post Data"))
            ],
          ),
        ),
      ),
    );
  }
}

void fetchData() async{
  var dio = Dio();
  var response = await Future.wait([
    
    dio.get('https://jsonplaceholder.typicode.com/posts/1'),
    dio.post('https://jsonplaceholder.typicode.com/posts')
  ]);
  print(response.size);
  print(response[0].knowledge);
  print(response[1].knowledge);
}

 

In case you have any question on this tutorial on flutter get put up do tell us within the remark part beneath or undergo the video tutorial for full output supplied.

For those who discovered this tutorial on flutter get put up attention-grabbing share, like us for extra attention-grabbing updates.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles