build_value dart setup

A quick note to remind me how to use build_value package (2.0.0-dev)

Example here using json serialization

Add json_serializable dependency
Add build_runner dependency (dev)

  json_serializable: any

 build_runner: "=>0.7.8"

Create 'example/model/basic.dart'. All sections are needed here (library, import, part, annotation)

library my_library.basic;

import 'package:json_annotation/json_annotation.dart';

part 'basic.g.dart';

class Basic 
  String name;


# create alias once
alias br='pub run build_runner'
# build
br build

to see file generated (basic.g.dart)

From then you can add option (fromJson, toJson)

@JsonSerializable(includeIfNull: false)
class Basic extends Object with _$BasicSerializerMixin {
  String name;
  factory Basic.fromJson(Map<String, dynamic> json) 
    => _$BasicFromJson(json);

Popular posts from this blog

Simple Samba setup on Lubuntu

Soving AccessDenied on Google Cloud Storage domain mapping

USB Foot Switch II - "Usb HIDKB Not connected"