igot_http_service 0.0.1
igot_http_service: ^0.0.1 copied to clipboard
This package contains a set of high-level functions and classes that make it easy to consume HTTP resources. It's multi-platform (mobile, desktop, and browser) and supports multiple implementations wi [...]
example/example.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:igot_http_service/services/http_service.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
ApiService.getApiRequest();
},
child: Text("Get Data"))
],
),
);
}
}
class ApiService {
static Future<dynamic> getApiRequest() async {
Response response = await HttpService.get(
apiUri: Uri.parse("https://jsonplaceholder.typicode.com/posts"),
ttl: Duration(minutes: 30));
var contents = jsonDecode(response.body);
return contents;
}
}