cv
1.1.15, released 11 days ago by tekartik.com
Helpers to convert Dart objects to/from Map and JSON without code generation.
What it does
cv provides a lightweight way to define models with fields and convert them to maps or JSON. It supports nested models, lists, maps, dates, enums and multi‑type fields, all without code generation.
AI-written summary of version 1.1.15, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need quick, mutable models that map to JSON or Map for local storage or API payloads.
- You want to avoid build_runner or codegen tooling for simple data structures.
- You need to handle null and unset values explicitly in your models.
Skip it when
- Your data models are large and complex, requiring performance optimisations or immutability.
- You rely heavily on code generation for type safety and boilerplate reduction (e.g., freezed).
Strengths
- No code generation required
- Easy to register and use models
- Handles null/unset values and type conversions
- Supports nested models and collections
Weaknesses
- Requires manual constructor registration
- Models are mutable, which may not fit all architectures
- No built‑in immutability or validation
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 4
Add dependency, register constructors with cvAddConstructor or cvAddConstructors before converting maps or JSON.
import 'package:cv/cv.dart';
class Todo extends CvModelBase {
final title = CvField<String>('title');
final done = CvField<bool>('done');
@override
CvFields get fields => [title, done];
}
void main() {
cvAddConstructor(Todo.new);
var todo = Todo()..title.v = 'Buy milk';
print(todo.toMap()); // {title: Buy milk}
var fromMap = {'title': 'Call Bob', 'done': true}.cv<Todo>();
print(fromMap.done.v); // true
}
Alternatives
Packages that do the same job and could replace cv.
- sortedmap
A map of objects which can be sorted and filtered on both their key and value.
82Compare - json_object_mapper
Map plain Dart objects to and from JSON without annotations or code generation
39Compare - json_schema
Validate JSON data against JSON Schema drafts in Dart.
63Compare - weak_map
A map whose keys are weakly held, and cache functions for memoization.
80Compare
Works with
Packages commonly used together with cv: ones it builds on, ones built on it, and its own family.