model_guard 0.0.6 copy "model_guard: ^0.0.6" to clipboard
model_guard: ^0.0.6 copied to clipboard

Automatic JSON parser for Flutter/Dart that logs model name, field name, and wrong values during parsing.

example/main.dart

import 'package:model_guard/model_guard.dart';

import '../lib/api__client_wrapper.dart';

class Product implements GuardModel {
  final int id;
  final String title;

  Product({required this.id, required this.title});

  factory Product.fromJson(Map<String, dynamic> json) {
    return Product(
      id: json['id'],
      title: json['title'],
    );
  }

  @override
  GuardModel fromJson(Map<String, dynamic> json) => Product.fromJson(json);
}

class FakeApiClient {
  Future<Map<String, dynamic>> get(String url) async {
    return {"id": 1, "title": "Phone"};
  }

  Future<List<dynamic>> getList(String url) async {
    return [
      {"id": 1, "title": "Phone"},
      {"id": 2, "title": "Laptop"}
    ];
  }
}

void main() async {
  final api = ApiWrapper<Product>(
    apiClient: FakeApiClient(),
    modelName: "Product",
    fromJson: (json) => Product.fromJson(json),
  );

  final product = await api.get("/product");

  print(product);
}
1
likes
0
points
117
downloads

Publisher

unverified uploader

Weekly Downloads

Automatic JSON parser for Flutter/Dart that logs model name, field name, and wrong values during parsing.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on model_guard