Flutter: http Rest api call
I am going to expect you have a new flutter and from that we will start modifying the code. To make it simple, I will divide the complete article into multiple small steps which will help you in following.
Step 1 #
First of all we need to use the package called http
. In order to use that you have to add the package name to the file pubspec.yaml
file
name: http_call_demo
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
http: ^0.12.2 # Added
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
Step 2 #
Let’s clear the main.dart file and write some code.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: HomePage(),
);
}
}
Step 3 #
Let’s make the home screen where we will be doing most of the thing.
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Http Call'),
),
);
}
}
Last updated at
Saturday, May 22, 2021
by
Nitish Kumar Singh