flutter_model_assert 0.0.3
flutter_model_assert: ^0.0.3 copied to clipboard
Early runtime validator for backend JSON responses to prevent type crashes and detect API contract mismatches in Flutter.
FlutterModelAssert #
A lightweight, runtime API contract validator for Flutter that prevents silent backend changes from crashing your app due to unexpected type or structure mismatches.
❗ Problem it solves #
Flutter apps rely on predefined Dart models to parse API responses.
When backend teams update an API field type (e.g., int → double, double → String, int → String, or rename/remove keys), Flutter throws errors like:
This causes:
- App crashes at runtime
- API parsing failures
- Broken UI or infinite loading states
- Time-consuming debugging to find the exact mismatched field
FlutterModelAssert detects these issues early and safely before parsing, giving clear error reports so developers can fix instantly.
✨ Features #
- Validates required keys in JSON responses
- Compares backend response types vs expected Dart model types
- Supports nested JSON validation
- Prevents runtime crashes by failing safely
- Provides exact field mismatch reports
- No code generation, no reflection (
dart:mirrors) needed - Ideal for QA, staging, and debug builds
- Works with
http,Dio, or any JSON source
🚀 Installation #
Add to pubspec.yaml:
dependencies:
flutter_model_assert: ^0.0.1
# flutter_model_assert