strint library
Safe JSON models — avoid UI crashes when the backend sends wrong types.
Use CreateModel spec + code generation to get freezed models with Safe*
converters. When the API returns e.g. int for a field you expected as
String?, the converter returns null instead of throwing.
1. Define models (YAML)
Create strint_models.yaml in your project:
ReportModel:
id: int?
dollar_rate: String?
2. Generate Dart code
dart run strint:generate
Then run build_runner for freezed:
dart run build_runner build --delete-conflicting-outputs
Classes
- SafeBool
- SafeDateTime
- ISO8601 DateTime ("2026-01-29T12:34:56Z" or with offset)
- SafeDouble
-
SafeEnum<
T extends Enum> - =============================== ENUM (supports String name or int index)
- SafeInt
- SafeMap
- =============================== MAP
-
SafeObject<
T> - =============================== OBJECT (Model)
-
SafeObjectList<
T> - LIST of objects (models)
-
SafePrimitiveList<
T> - =============================== LIST of primitive
- SafeString
- =============================== PRIMITIVES
Functions
-
CreateModel(
String modelName, Map< String, String> fields) → String - Generates the freezed + Safe* model Dart source.
-
generateModel(
{required String modelName, required Map< String, String> fields, String safeJsonImport = "package:strint/safe_json.dart", String freezedImport = "package:freezed_annotation/freezed_annotation.dart", String jsonKeyImport = "package:json_annotation/json_annotation.dart"}) → String - Generates the Dart source for a single freezed model.
-
resolveType(
String typeKey) → (String, String) - Resolves Dart type and Safe converter annotation for a type string. Returns (dartType, converterName) e.g. ("int?", "SafeInt").
-
snakeCaseFileName(
String modelName) → String -
snakeToCamel(
String s) → String - Converts snake_case to camelCase.