Skip to content

Instantly share code, notes, and snippets.

@peekpt
Created February 19, 2019 20:45
Show Gist options
  • Select an option

  • Save peekpt/27d8f5f1541535a90ebb3f18a14167cf to your computer and use it in GitHub Desktop.

Select an option

Save peekpt/27d8f5f1541535a90ebb3f18a14167cf to your computer and use it in GitHub Desktop.

Revisions

  1. peekpt created this gist Feb 19, 2019.
    53 changes: 53 additions & 0 deletions Flutter built value snippet
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    {
    "Built Value": {
    "prefix": "blt",
    "body": [
    "abstract class ${1} implements Built<${1}, ${1}Builder> {",
    "\t${0:// fields go here}",
    "",
    "\t${1}._();",
    "",
    "\tfactory ${1}([updates(${1}Builder b)]) = _$${1};",
    "}"
    ],
    "description": "Built Value Class"
    },
    "Built Value Serializable": {
    "prefix": "blts",
    "body": [
    "abstract class ${1} implements Built<${1}, ${1}Builder> {",
    "\t${0:// fields go here}",
    "",
    "\t${1}._();",
    "",
    "\tfactory ${1}([updates(${1}Builder b)]) = _$${1};",
    "",
    "\tString toJson() {",
    "\t\treturn json.encode(serializers.serializeWith(${1}.serializer, this));",
    "\t}",
    "",
    "\tstatic ${1} fromJson(String jsonString) {",
    "\t\treturn serializers.deserializeWith(${1}.serializer, json.decode(jsonString));",
    "\t}",
    "",
    "\tstatic Serializer<${1}> get serializer => _$${1/(^[A-z]{1})/${1:/downcase}/}Serializer;",
    "}"
    ],
    "description": "Serializable Built Value Class"
    },
    "Built Value Header": {
    "prefix": "blth",
    "body": [
    "library ${1};",
    "",
    "import 'dart:convert';",
    "",
    "import 'package:built_collection/built_collection.dart';",
    "import 'package:built_value/built_value.dart';",
    "import 'package:built_value/serializer.dart';",
    "",
    "part '${1}.g.dart';",
    ],
    "description": "Built Value Imports and File Header"
    },
    }