Last updated:
0 purchases
http manage
http_manage #
Manage Http Request #
Note: this package use http package #
watch video
Description #
This package is will return custom model list.
Example #
import 'package:http_manage/http_manage.dart';
List<PostModel> posts = await httpManage
.getRequestWithModel('/posts', PostModel(), showDialog: true);
print(posts.runtimeType); //Instance of PostModel
copied to clipboard
Usage #
main.js #
import 'package:http_manage/http_manage.dart';
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: navigatorKey,
copied to clipboard
import navigatorKey from http_package. with navigatorKey we can show alertDialog everywhere
Create Instance #
HttpManage httpManage =
HttpManage(endPoint: 'https://jsonplaceholder.typicode.com');
copied to clipboard
Constructor Values #
If you want you can optimize constructor values
HttpManage(
{@required this.endPoint,
bool showDialog = false,
this.onSuccessTitle = 'Awesome 😻',
this.onSuccessMessage = 'Success',
this.onErrorTitle = 'Sorry 😿',
this.backButtonText = 'Back',
this.onErrorMessage = 'An Error Occured Please Try Again'});
copied to clipboard
HttpManage httpManage =
HttpManage(
endPoint: 'https://jsonplaceholder.typicode.com',
onSuccessTitle: 'İşlem Başarılı',
onSuccessMessage: 'Verileriniz Güncellenmiştir'
);
copied to clipboard
Model Class #
Your Model Class Should be extends and determine generic type
Override fromJson function from BaseModel Class
import 'package:http_manage/http_manage.dart';
class PostModel extends BaseModel<PostModel> {
int userId;
int id;
String title;
String body;
PostModel({this.userId, this.id, this.title, this.body});
@override
PostModel fromJson(Map<String, dynamic> json) {
return PostModel(
userId: json['userId'],
id: json['id'],
title: json['title'],
body: json['body']);
}
}
copied to clipboard
Send Request #
Future<List<PostModel>> getPosts() async {
List<PostModel> posts = await httpManage
.getRequestWithModel('/posts', PostModel(), showDialog: true);
print(posts.runtimeType);
return posts;
}
copied to clipboard
Keys #
if you want select custom key in json then use keys
keys should be List<String>
Another EndPoint #
if you need to send request to antoher endpoint then you can use anotherEndPoint param
if anotherEndPoint equal to null automatically gona use default endpoint from constructor
testKeys() async {
var result = await httpManage.getRequest(
'?resource_id=d588f256-2982-43d2-b372-c38978d7200b',
keys: ['result', 'records'],
anotherEndPoint:
'https://data.ibb.gov.tr/api/3/action/datastore_search');
print(result);
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.