Skip to content

Instantly share code, notes, and snippets.

@tackme31
Created September 16, 2024 19:27
Show Gist options
  • Save tackme31/ca5ba6ed76473f88a059b5058be9e316 to your computer and use it in GitHub Desktop.
Save tackme31/ca5ba6ed76473f88a059b5058be9e316 to your computer and use it in GitHub Desktop.
VSCode snippet that generates freezed and riverpod_generator templates
{
"Generate Riverpod Notifier": {
"scope": "dart",
"prefix": "rvnp",
"body": [
"import 'package:riverpod_annotation/riverpod_annotation.dart';",
"",
"part '$TM_FILENAME_BASE.g.dart';",
"",
"@Riverpod(dependencies: [])",
"class ${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g} extends _\\$${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g} {",
" @override",
" ${1:type} build() {",
" throw UnimplementedError();",
" }",
"}",
]
},
"Generate Riverpod AsyncNotifier": {
"scope": "dart",
"prefix": "rvanp",
"body": [
"import 'package:riverpod_annotation/riverpod_annotation.dart';",
"",
"part '$TM_FILENAME_BASE.g.dart';",
"",
"@Riverpod(dependencies: [])",
"class ${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g} extends _\\$${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g} {",
" @override",
" Future<${1:type}> build() async {",
" throw UnimplementedError();",
" }",
"}",
]
},
"Generate Freezed class": {
"scope": "dart",
"prefix": "frz",
"body": [
"import 'package:freezed_annotation/freezed_annotation.dart';",
"",
"part '$TM_FILENAME_BASE.freezed.dart';",
"",
"@freezed",
"class ${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g} with _$${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g} {",
" const factory ${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g}(${1}) = _${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g};",
"}",
]
},
"Generate Freezed class with JSON": {
"scope": "dart",
"prefix": "frzj",
"body": [
"import 'package:freezed_annotation/freezed_annotation.dart';",
"",
"part '$TM_FILENAME_BASE.freezed.dart';",
"part '$TM_FILENAME_BASE.g.dart';",
"",
"@freezed",
"class ${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g} with _$${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g} {",
" const factory ${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g}(${1}) = _${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g};",
"",
" factory ${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g}.fromJson(Map<String, dynamic> json) => _$${TM_FILENAME_BASE/(_|^)(.)/${2:/upcase}/g}FromJson(json);",
"}",
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment