dynatype 1.0.4 copy "dynatype: ^1.0.4" to clipboard
dynatype: ^1.0.4 copied to clipboard

outdated

The package helps developers make the process easy by validating the response of type JSON. The person using this package does not need to worry about any exception in JSON Map Entries. He can define [...]

DynaType #

pub package Build status style: effective dart

DynaType is a flutter plugin that provides robust control on JSON Response and Request. This plugin gives you the name of the key and its value data type, which were incorrectly parsed before executing any logic, so that you can show an error in response to the request.

Features #

  • Get the Missing Fields;
  • Get the Missing Fields Data Type;
  • Check the request is perfect;
  • Declare your own request key and types;

IMPORTANT:

Dyna Types is still in its development phase. It is created to support the backend and middleware server created using Dart. DynaType will help developers check their requests and validate them before executing any functions.

Usage #

To add DynaType to your project, you need to import dynatype package to your project dependency.

  • You need to define an instance of DynaCheck where you will pass the response of JSON and create a list using DynaType, which will determine how your JSON Response should look.
  • Use the instance you got and run the verifyfields() function.
  • verifyfields() function will provide you DynaFields, which contains bool isEmpty and a list of List
  • isEmpty provides TRUE if the JSON Response was correct or provides FALSE.
  • If isEmpty is false. You can get invalid MapEntries keys and datatypes from using .notfound on verifyfields Function.

Example #

The code below shows how to use DynaType and acquire all the invalid parsed values and their data types.

import 'dart:convert';
import 'package:dynatype/dynacheck.dart';
import 'package:dynatype/dynatype.dart';

//This is My json List which i will receive in response or request.
//You can try removing fields and text it.
final json = {
  "book": '{"name": "200","author":"Lin god"}',
  "language": "english",
  "language2": "english",
  "publish": 1988
};

void main() {
  //Here i am defining the fields i required.
  final List<DynaType> _requiredMain = [
    DynaType(key: "book", type: String),
    DynaType(key: "language", type: String),
    DynaType(key: "language2", type: String),
    DynaType(key: "publish", type: int),
  ];

  final List<DynaType> _requiredBook = [
    DynaType(key: "name", type: String),
    DynaType(key: "author", type: String),
  ];

  //this is the [instance.verifyFields()] function which returns the missing, null and wrong data type Keys.
  DynaCheck main = DynaCheck(data: json, presence: _requiredMain);

  if (main.verifyFields().isEmpty) {
    //Data always accepts Map you cannot pass an object inside the data as it a request.
    DynaCheck book = DynaCheck(
        data: jsonDecode(json["book"].toString()), presence: _requiredBook);
    if (book.verifyFields().isEmpty) {
      print("The response is correct");
    } else {
      print("Missing or incorrect fields ${book.verifyFields().notFound.dyna}");
    }
  }
}
3
likes
0
pub points
0%
popularity

Publisher

verified publisherlivnium.com

The package helps developers make the process easy by validating the response of type JSON. The person using this package does not need to worry about any exception in JSON Map Entries. He can define a pattern for the JSON response using DynaType.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

equatable

More

Packages that depend on dynatype