Table of Contents
Flutter GET Post :
Flutter GET Publish both the community phone calls are executed concurrently employing dio library is discussed in this aspect of the tutorial.
Api phone calls are categorized dependent on the function they do like producing information we make use of Put up, fetching the knowledge we make use of GET, updating the details we make us of Set, deleting the info we use DELETE.
These are the several varieties i have specified you can discover considerably additional information and facts at https://www.amplifyabhi.com/2022/06/10/http-response-codes/
It may sound really attention-grabbing to execute the two at after we have clearly discussed this circumstance by a video tutorial.
We have viewed the unique implementation of flutter dio GET. And comprehensive perform listing of tutorial is offered listed here.
https://www.youtube.com/observe?v=o8aRL6-mIq0
pubspec.yaml:
Insert dio library to your pubspec file. Offer the hottest model to steer clear of unwanted problems.
dependencies: flutter: sdk: flutter dio: ^4..6
primary.dart :
We will be executing the two GET and Write-up implementations for a provided api’s and will fetch the reaction at once applying array record.
Can fetch the information according to the positions.
Provide GET ask for
dio.get('https://jsonplaceholder.typicode.com/posts/1'),
Present Write-up request
dio.submit('https://jsonplaceholder.typicode.com/posts')
can fetch the details as
print(reaction[0].knowledge) print(response[1].details)
create a dio object and make api get in touch with.
var dio = Dio()
You can locate the duration of the array as
response.size
Provide a simple code to make a button simply click so that api get in touch with can be commenced.
Column( mainAxisAlignment: MainAxisAlignment.centre, young children: [ TextButton(onPressed: () fetchData(); , child: const Text("Get / Post Data")) ], ),
void fetchData() async var dio = Dio() var response = await Potential.wait around([ dio.get('https://jsonplaceholder.typicode.com/posts/1'), dio.post('https://jsonplaceholder.typicode.com/posts') ]) print(response.duration) print(response[0].details) print(reaction[1].information)
Delivering the whole code for api implementation.
import 'package:dio/dio.dart' import 'package:flutter/materials.dart' void main() runApp(const MyApp()) class MyApp extends StatelessWidget const MyApp(Essential? crucial) : tremendous(important: vital) @override Widget establish(BuildContext context) return MaterialApp( dwelling: Scaffold( overall body: Middle( little one: 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.duration) print(reaction[0].information) print(response[1].knowledge)
If you have any query in this tutorial do permit us know in the remark area down below or go by means of the online video tutorial for entire output delivered.
If you uncovered this tutorial fascinating share, like us for additional interesting updates.