Loading topic
Intermediate · Mid: 15 chapters · 24 min read. States assumed prerequisites
Start readingMap and List, and the basic structure of a Flutter project. You should also know that a REST API returns JSON text.Map<String, dynamic>, and the basic structure of a Flutter project. This chapter also assumes that json_annotation, json_serializable, and build_runner are already listed in pubspec.yaml.pubspec.yaml, and basic JSON maps. You should also have a Flutter project and a model annotated with @JsonSerializable.json_serializable setup. This chapter focuses on controlling how one Dart field maps to one JSON key. The generated code still performs the conversion, but @JsonKey supplies the rules.json_serializable workflow. You should also know that fromJson reads a Map<String, dynamic> and toJson creates one.json_serializable converts nested JSON objects and lists into typed Dart objects.json_serializable models. You will use generated code rather than writing fromJson and toJson by hand.json_serializable workflow. This chapter focuses on fields whose JSON representation does not match the Dart type directly.dart:convert, and how json_serializable generates fromJson methods. This chapter focuses on failures that happen when an API returns invalid text or a valid JSON value with the wrong shape.Map<String, dynamic>, Flutter tests, and the json_serializable setup from earlier chapters. A round-trip test checks that a model can be encoded to JSON and decoded back without losing meaningful data.json_serializable workflow. This chapter shows how to serialize a class whose field type is a type parameter, such as ApiResponse<T>.Future, jsonDecode, and the generated fromJson methods from json_serializable. It also assumes you have a model such as User with a generated User.fromJson method.Map<String, dynamic>, and the basic role of json_serializable. This chapter compares related tools so you can choose a suitable approach instead of adding code generation automatically.