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

Usage

main.js

import 'package:http_manage/http_manage.dart';

Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: navigatorKey,

import navigatorKey from http_package. with navigatorKey we can show alertDialog everywhere

Create Instance

HttpManage httpManage =
    HttpManage(endPoint: 'https://jsonplaceholder.typicode.com');

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'});
 HttpManage httpManage =
    HttpManage(
        endPoint: 'https://jsonplaceholder.typicode.com',
        onSuccessTitle: '─░┼člem Ba┼čar─▒l─▒',
        onSuccessMessage: 'Verileriniz G├╝ncellenmi┼čtir'
    );

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']);
  }
}

Send Request

Future<List<PostModel>> getPosts() async {
    List<PostModel> posts = await httpManage
        .getRequestWithModel('/posts', PostModel(), showDialog: true);
    print(posts.runtimeType);
    return posts;
  }

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);
  }

Libraries

http_manage