xxxxxxxxxx
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
void getData() async {
var url = Uri.parse('https://jsonplaceholder.typicode.com/todos/1');
var response = await http.get(url);
Map data = jsonDecode(response.body); // this requires import dart:convert
print(data);
}
xxxxxxxxxx
Future<int> getSettings(int i) async {
final url = Uri.parse(ApiLinks.settingsUrl + "/settings");
try {
http.Response response = await http.get(url,
headers: {
'Authorization': ApiLinks.token
});
if (response.statusCode == 200) {
var res = jsonDecode(response.body);
//print(" res = "+res.toString());
print(" res0 = "+res["StatusMessage"][i]["value_setting"].toString());
return res["StatusMessage"][i]["value_setting"];
}
return 0;
} catch (e) {
print("Settings Api Get, error occurred " + e.toString());
return 0;
}
}
xxxxxxxxxx
import 'package:http/http.dart' as http;
void fetchData() async {
var url = 'https://api.example.com/data';
try {
var response = await http.get(url);
if (response.statusCode == 200) {
// Successful response
var data = response.body;
// Process the fetched data here
print(data);
} else {
// Handle error response
print('Request failed with status: ${response.statusCode}.');
}
} catch (e) {
// Handle any exceptions during the request
print('Error: $e');
}
}