Last active
February 5, 2024 17:24
-
-
Save PlugFox/d8be4aba16ef3a37bd1dc572b46ebdbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Changelog unreleased": { | |
"scope": "md, markdown", | |
"prefix": "changelog_unreleased", | |
"description": "Changelog unreleased", | |
"body": [ | |
"# Unreleased", | |
"+ added: ${0}", | |
"+ changed: ", | |
"+ deprecated: ", | |
"+ removed: ", | |
"+ fixed: ", | |
"+ security: ", | |
"+ refactor: ", | |
"+ docs: ", | |
" " | |
] | |
}, | |
"Changelog version": { | |
"scope": "md, markdown", | |
"prefix": "changelog_version", | |
"description": "Changelog version section", | |
"body": [ | |
"# ${1:0}.${2:0}.${3:0}", | |
"+ added: ${0}", | |
"+ changed: ", | |
"+ deprecated: ", | |
"+ removed: ", | |
"+ fixed: ", | |
"+ security: ", | |
"+ refactor: ", | |
"+ docs: ", | |
" " | |
] | |
}, | |
"New dartdoc template": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"dartdoc_create_template", | |
"new_dartdoc_template", | |
"newtmpl", | |
], | |
"description": "Creates a new dartdoc template with current file's name as its prefix", | |
"body": [ | |
"/// {@template $TM_FILENAME_BASE.${1}}", | |
"/// $0", | |
"/// {@endtemplate}" | |
] | |
}, | |
"Dartdoc macro": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"dartdoc_use_template", | |
"usetmpl" | |
], | |
"description": "Uses existing dartdoc macro with current file's name as its prefix", | |
"body": "/// {@macro $TM_FILENAME_BASE.$0}" | |
}, | |
"Comment": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"cmnt", | |
"comment" | |
], | |
"description": "Comment block", | |
"body": "// --- ${1} --- //\n\n$0" | |
}, | |
"Divider": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"dvd", | |
"divider_comment" | |
], | |
"description": "Divider comment line", | |
"body": "// --- ${1} --- //\n\n$0" | |
}, | |
"Create new class": { | |
"scope": "flutter, dart", | |
"prefix": "class", | |
"description": "Create new class", | |
"body": [ | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} class", | |
"/// {@endtemplate}", | |
"class ${1} {", | |
" /// {@macro $TM_FILENAME_BASE.${2}}", | |
" const ${1}($0);", | |
" ", | |
"} // ${1}\n" | |
] | |
}, | |
"Data class": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"entity", | |
"dataClass", | |
"classData" | |
], | |
"description": "Create new class", | |
"body": [ | |
"import 'package:meta/meta.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} entity", | |
"/// {@endtemplate}", | |
"@immutable", | |
"// ignore: prefer_mixin", | |
"class ${1} with Comparable<${1}> {", | |
" /// {@macro $TM_FILENAME_BASE.${2}}", | |
" ${1}({", | |
" required this.id,", | |
" required this.title,", | |
" this.description = '',", | |
" DateTime? updated,", | |
" DateTime? created,", | |
" }) : updated = updated ?? DateTime.now(),", | |
" created = created ?? updated ?? DateTime.now();${0}", | |
"", | |
" /// The unique identifier for this object.", | |
" final int id;", | |
"", | |
" /// The title of this object.", | |
" final String title;", | |
"", | |
" /// A short description of this object.", | |
" final String description;", | |
"", | |
" /// The date this object was last updated.", | |
" final DateTime updated;", | |
"", | |
" /// The date this object was created.", | |
" final DateTime created;", | |
"", | |
" /// Generate Class from Map<String, Object?>", | |
" factory ${1}.fromJson(Map<String, Object?> json) => ${1}(", | |
" id: (json['id'] as int?)!,", | |
" title: (json['title'] as String?)!,", | |
" description: (json['description'] as String?)!,", | |
" updated: DateTime.parse((json['updated'] as String?)!).toLocal(),", | |
" created: DateTime.parse((json['created'] as String?)!).toLocal(),", | |
" );", | |
"", | |
" /// Generate Map<String, Object?> from class", | |
" Map<String, Object?> toJson() => <String, Object?>{", | |
" 'id': id,", | |
" 'title': title,", | |
" 'description': description,", | |
" 'updated': updated.toUtc().toIso8601String(),", | |
" 'created': created.toUtc().toIso8601String(),", | |
" };", | |
"", | |
" /// Create a copy of this object with the given values.", | |
" ${1} copyWith({", | |
" int? newId,", | |
" String? newTitle,", | |
" String? newDescription,", | |
" DateTime? newUpdated,", | |
" DateTime? newCreated,", | |
" }) =>", | |
" ${1}(", | |
" id: newId ?? id,", | |
" title: newTitle ?? title,", | |
" description: newDescription ?? description,", | |
" updated: newUpdated ?? DateTime.now(),", | |
" created: newCreated ?? created,", | |
" );", | |
"", | |
" @override", | |
" int compareTo(${1} other) => id.compareTo(other.id);", | |
"", | |
" @override", | |
" int get hashCode => id;", | |
"", | |
" @override", | |
" bool operator ==(Object other) =>", | |
" identical(this, other) ||", | |
" other is ${1} && runtimeType == other.runtimeType && id == other.id;", | |
"", | |
" @override", | |
" String toString() => '${1}#\\$id';", | |
"", | |
"} // ${1}\n" | |
] | |
}, | |
"Part": { | |
"scope": "flutter, dart", | |
"prefix": "part", | |
"description": "Part of file", | |
"body": [ | |
"part '${TM_FILENAME_BASE}.g.dart';$0" | |
] | |
}, | |
"Mocks": { | |
"scope": "flutter, dart", | |
"prefix": "mocks", | |
"description": "Import mocks file", | |
"body": [ | |
"import '${TM_FILENAME_BASE}.mocks.dart';$0" | |
] | |
}, | |
"Sign": { | |
"scope": "flutter, dart", | |
"prefix": "sign", | |
"description": "Insert my sign", | |
"body": [ | |
"${BLOCK_COMMENT_START}", | |
" * $0", | |
" * Matiunin Mikhail <[email protected]>, ${CURRENT_DATE} ${CURRENT_MONTH_NAME} ${CURRENT_YEAR}", | |
" ${BLOCK_COMMENT_END}" | |
] | |
}, | |
"Dart Pad": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"pad", | |
"dartPad", | |
], | |
"description": "Insert my sign for dart pad", | |
"body": [ | |
"${BLOCK_COMMENT_START}", | |
" * $0", | |
" * https://gist.github.com/PlugFox/${1}", | |
" * https://dartpad.dev/${1}", | |
" * Matiunin Mikhail <[email protected]>, ${CURRENT_DATE} ${CURRENT_MONTH_NAME} ${CURRENT_YEAR}", | |
" ${BLOCK_COMMENT_END}" | |
] | |
}, | |
"ToDo": { | |
"scope": "flutter, dart", | |
"prefix": "todo", | |
"description": "ToDo block", | |
"body": [ | |
"${LINE_COMMENT} TODO: $0", | |
"${LINE_COMMENT} Matiunin Mikhail <[email protected]>, ${CURRENT_DATE} ${CURRENT_MONTH_NAME} ${CURRENT_YEAR}" | |
] | |
}, | |
"Hash Code": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"hashCode", | |
"equals", | |
"==" | |
], | |
"description": "Hash Code and Equals override", | |
"body": [ | |
"@override", | |
"int get hashCode => id.hashCode;\n", | |
"@override", | |
"bool operator ==(Object other) =>", | |
" identical(this, other) ||", | |
" other is ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} &&", | |
" runtimeType == other.runtimeType &&", | |
" id == other.id;${0}\n" | |
] | |
}, | |
"BLoC": { | |
"scope": "flutter, dart", | |
"prefix": "bloc", | |
"description": "Buisness Logic Component", | |
"body": [ | |
"import 'dart:async';\n", | |
"import 'package:bloc/bloc.dart';", | |
"import 'package:bloc_concurrency/bloc_concurrency.dart' as bloc_concurrency;", | |
"import 'package:freezed_annotation/freezed_annotation.dart';", | |
"import 'package:l/l.dart';\n", | |
"part '${TM_FILENAME_BASE}.freezed.dart';\n", | |
"/* ${1:${TM_FILENAME_BASE/(^[a-zA-Z]{1})(.*)(bloc)/${1:/upcase}${2:/camelcase}/g}} Events */\n", | |
"@freezed", | |
"class ${1}Event with _$${1}Event {", | |
" const ${1}Event._();\n", | |
" const factory ${1}Event.create() = Create${1}Event;\n", | |
" const factory ${1}Event.read() = Read${1}Event;\n", | |
" const factory ${1}Event.update() = Update${1}Event;\n", | |
" const factory ${1}Event.delete() = Delete${1}Event;", | |
"}\n", | |
"/* ${1} States */\n", | |
"@freezed", | |
"class ${1}State with _$${1}State {", | |
" const ${1}State._();\n", | |
" /// Is in idle state", | |
" bool get idling => !isProcessing;\n", | |
" /// Is in progress state", | |
" bool get isProcessing => maybeMap<bool>(", | |
" orElse: () => true,", | |
" idle: (_) => false,", | |
" );\n", | |
" /// If an error has occurred", | |
" bool get hasError => maybeMap<bool>(orElse: () => false, error: (_) => true);\n", | |
" /// Idling state", | |
" const factory ${1}State.idle({", | |
" required final ${1}Entity data,", | |
" @Default('Idle') final String message,", | |
" }) = Idle${1}State;\n", | |
" /// Processing", | |
" const factory ${1}State.processing({", | |
" required final ${1}Entity data,", | |
" @Default('Processing') final String message,", | |
" }) = Processing${1}State;\n", | |
" /// Successful", | |
" const factory ${1}State.successful({", | |
" required final ${1}Entity data,", | |
" @Default('Successful') final String message,", | |
" }) = Successful${1}State;\n", | |
" /// An error has occurred", | |
" const factory ${1}State.error({", | |
" required final ${1}Entity data,", | |
" @Default('An error has occurred') final String message,", | |
" }) = Error${1}State;", | |
"}\n", | |
"/// Buisiness Logic Component ${1}BLoC", | |
"class ${1}BLoC extends Bloc<${1}Event, ${1}State> implements EventSink<${1}Event> {", | |
" ${1}BLoC({", | |
" required final I${1}Repository repository,", | |
" final ${1}State? initialState,", | |
" }) : _repository = repository,", | |
" super(", | |
" initialState ??", | |
" ${1}State.idle(", | |
" data: ${1}Entity(),", | |
" message: 'Initial idle state',", | |
" ),", | |
" ) {", | |
" on<${1}Event>(", | |
" (event, emit) => event.map<Future<void>>(", | |
" create: (event) => _create(event, emit),", | |
" read: (event) => _read(event, emit),", | |
" update: (event) => _update(event, emit),", | |
" delete: (event) => _delete(event, emit),", | |
" ),", | |
" transformer: bloc_concurrency.sequential(),", | |
" //transformer: bloc_concurrency.restartable(),", | |
" //transformer: bloc_concurrency.droppable(),", | |
" //transformer: bloc_concurrency.concurrent(),", | |
" );$0", | |
" }", | |
" ", | |
" final I${1}Repository _repository;", | |
" ", | |
" /// Create event handler", | |
" Future<void> _create(Create${1}Event event, Emitter<${1}State> emit) async {", | |
" try {", | |
" emit(${1}State.processing(data: state.data));", | |
" //final newData = await _repository.();", | |
" emit(${1}State.successful(data: newData));", | |
" } on Object catch (err, stackTrace) {", | |
" l.e('В ${1}BLoC произошла ошибка: \\$err', stackTrace);", | |
" emit(${1}State.error(data: state.data));", | |
" rethrow;", | |
" } finally {", | |
" emit(${1}State.idle(data: state.data));", | |
" }", | |
" }", | |
" ", | |
" /// Read event handler", | |
" Future<void> _read(Read${1}Event event, Emitter<${1}State> emit) async {", | |
" try {", | |
" emit(${1}State.processing(data: state.data));", | |
" //final newData = await _repository.();", | |
" emit(${1}State.successful(data: newData));", | |
" } on Object catch (err, stackTrace) {", | |
" l.e('В ${1}BLoC произошла ошибка: \\$err', stackTrace);", | |
" emit(${1}State.error(data: state.data));", | |
" rethrow;", | |
" } finally {", | |
" emit(${1}State.idle(data: state.data));", | |
" }", | |
" }", | |
" ", | |
" /// Update event handler", | |
" Future<void> _update(Update${1}Event event, Emitter<${1}State> emit) async {", | |
" try {", | |
" emit(${1}State.processing(data: state.data));", | |
" //final newData = await _repository.();", | |
" emit(${1}State.successful(data: newData));", | |
" } on Object catch (err, stackTrace) {", | |
" l.e('В ${1}BLoC произошла ошибка: \\$err', stackTrace);", | |
" emit(${1}State.error(data: state.data));", | |
" rethrow;", | |
" } finally {", | |
" emit(${1}State.idle(data: state.data));", | |
" }", | |
" }", | |
" ", | |
" /// Delete event handler", | |
" Future<void> _delete(Delete${1}Event event, Emitter<${1}State> emit) async {", | |
" try {", | |
" emit(${1}State.processing(data: state.data));", | |
" //final newData = await _repository.();", | |
" emit(${1}State.successful(data: newData));", | |
" } on Object catch (err, stackTrace) {", | |
" l.e('В ${1}BLoC произошла ошибка: \\$err', stackTrace);", | |
" emit(${1}State.error(data: state.data));", | |
" rethrow;", | |
" } finally {", | |
" emit(${1}State.idle(data: state.data));", | |
" }", | |
" }", | |
"}" | |
] | |
}, | |
"BLoC Extended": { | |
"scope": "flutter, dart", | |
"prefix": "blocExtended", | |
"description": "Buisness Logic Component with mixins", | |
"body": [ | |
"import 'dart:async';\n", | |
"import 'package:bloc/bloc.dart';", | |
"import 'package:bloc_concurrency/bloc_concurrency.dart' as bloc_concurrency;", | |
"import 'package:freezed_annotation/freezed_annotation.dart';", | |
"import 'package:l/l.dart';\n", | |
"part '${TM_FILENAME_BASE}.freezed.dart';\n", | |
"/* ${1:${TM_FILENAME_BASE/(^[a-zA-Z]{1})(.*)(bloc)/${1:/upcase}${2:/camelcase}/g}} Events */\n", | |
"@freezed", | |
"class ${1}Event with _$${1}Event {", | |
" const ${1}Event._();\n", | |
" @Implements<I${1}Event>()", | |
" @With<_ProcessingStateEmitter>()", | |
" @With<_SuccessfulStateEmitter>()", | |
" @With<_ErrorStateEmitter>()", | |
" @With<_IdleStateEmitter>()", | |
" const factory ${1}Event.create() = Create${1}Event;\n", | |
" @Implements<I${1}Event>()", | |
" @With<_ProcessingStateEmitter>()", | |
" @With<_SuccessfulStateEmitter>()", | |
" @With<_ErrorStateEmitter>()", | |
" @With<_IdleStateEmitter>()", | |
" const factory ${1}Event.read() = Read${1}Event;\n", | |
" @Implements<I${1}Event>()", | |
" @With<_ProcessingStateEmitter>()", | |
" @With<_SuccessfulStateEmitter>()", | |
" @With<_ErrorStateEmitter>()", | |
" @With<_IdleStateEmitter>()", | |
" const factory ${1}Event.update() = Update${1}Event;\n", | |
" @Implements<I${1}Event>()", | |
" @With<_ProcessingStateEmitter>()", | |
" @With<_SuccessfulStateEmitter>()", | |
" @With<_ErrorStateEmitter>()", | |
" @With<_IdleStateEmitter>()", | |
" const factory ${1}Event.delete() = Delete${1}Event;", | |
"}\n", | |
"/* ${1} States */\n", | |
"@freezed", | |
"class ${1}State with _$${1}State {", | |
" const ${1}State._();\n", | |
" /// Is in idle state", | |
" bool get idling => !isProcessing;\n", | |
" /// Is in progress state", | |
" bool get isProcessing => maybeMap<bool>(", | |
" orElse: () => true,", | |
" idle: (_) => false,", | |
" );\n", | |
" /// If an error has occurred", | |
" bool get hasError => maybeMap<bool>(orElse: () => false, error: (_) => true);\n", | |
" /// Idling state", | |
" const factory ${1}State.idle({", | |
" required final ${1}Entity data,", | |
" @Default('Idle') final String message,", | |
" }) = Idle${1}State;\n", | |
" /// Processing", | |
" const factory ${1}State.processing({", | |
" required final ${1}Entity data,", | |
" @Default('Processing') final String message,", | |
" }) = Processing${1}State;\n", | |
" /// Successful", | |
" const factory ${1}State.successful({", | |
" required final ${1}Entity data,", | |
" @Default('Successful') final String message,", | |
" }) = Successful${1}State;\n", | |
" /// An error has occurred", | |
" const factory ${1}State.error({", | |
" required final ${1}Entity data,", | |
" @Default('An error has occurred') final String message,", | |
" }) = Error${1}State;", | |
"}\n", | |
"/// Buisiness Logic Component ${1}BLoC", | |
"class ${1}BLoC extends Bloc<${1}Event, ${1}State> implements EventSink<${1}Event> {", | |
" ${1}BLoC({", | |
" required final I${1}Repository repository,", | |
" final ${1}State? initialState,", | |
" }) : _repository = repository,", | |
" super(", | |
" initialState ??", | |
" ${1}State.idle(", | |
" data: ${1}Entity(),", | |
" message: 'Initial idle state',", | |
" ),", | |
" ) {", | |
" on<${1}Event>(", | |
" (event, emit) => event.map<Future<void>>(", | |
" create: (event) => _create(event, emit),", | |
" read: (event) => _read(event, emit),", | |
" update: (event) => _update(event, emit),", | |
" delete: (event) => _delete(event, emit),", | |
" ),", | |
" transformer: bloc_concurrency.sequential(),", | |
" //transformer: bloc_concurrency.restartable(),", | |
" //transformer: bloc_concurrency.droppable(),", | |
" //transformer: bloc_concurrency.concurrent(),", | |
" );$0", | |
" }", | |
" ", | |
" final I${1}Repository _repository;", | |
" ", | |
" /// Create event handler", | |
" Future<void> _create(Create${1}Event event, Emitter<${1}State> emit) async {", | |
" try {", | |
" emit(event.inProgress(state: state));", | |
" //final newData = await _repository.();", | |
" emit(event.successful(state: state, newData: newData));", | |
" } on Object catch (err, stackTrace) {", | |
" l.e('В ${1}BLoC произошла ошибка: \\$err', stackTrace);", | |
" emit(event.error(state: state, message: 'An error occurred'));", | |
" rethrow;", | |
" } finally {", | |
" emit(event.idle(state: state));", | |
" }", | |
" }", | |
" ", | |
" /// Read event handler", | |
" Future<void> _read(Read${1}Event event, Emitter<${1}State> emit) async {", | |
" try {", | |
" emit(event.inProgress(state: state));", | |
" //final newData = await _repository.();", | |
" emit(event.successful(state: state, newData: newData));", | |
" } on Object catch (err, stackTrace) {", | |
" l.e('В ${1}BLoC произошла ошибка: \\$err', stackTrace);", | |
" emit(event.error(state: state, message: 'An error occurred'));", | |
" rethrow;", | |
" } finally {", | |
" emit(event.idle(state: state));", | |
" }", | |
" }", | |
" ", | |
" /// Update event handler", | |
" Future<void> _update(Update${1}Event event, Emitter<${1}State> emit) async {", | |
" try {", | |
" emit(event.inProgress(state: state));", | |
" //final newData = await _repository.();", | |
" emit(event.successful(state: state, newData: newData));", | |
" } on Object catch (err, stackTrace) {", | |
" l.e('В ${1}BLoC произошла ошибка: \\$err', stackTrace);", | |
" emit(event.error(state: state, message: 'An error occurred'));", | |
" rethrow;", | |
" } finally {", | |
" emit(event.idle(state: state));", | |
" }", | |
" }", | |
" ", | |
" /// Delete event handler", | |
" Future<void> _delete(Delete${1}Event event, Emitter<${1}State> emit) async {", | |
" try {", | |
" emit(event.inProgress(state: state));", | |
" //final newData = await _repository.();", | |
" emit(event.successful(state: state, newData: newData));", | |
" } on Object catch (err, stackTrace) {", | |
" l.e('В ${1}BLoC произошла ошибка: \\$err', stackTrace);", | |
" emit(event.error(state: state, message: 'An error occurred'));", | |
" rethrow;", | |
" } finally {", | |
" emit(event.idle(state: state));", | |
" }", | |
" }", | |
"}", | |
"", | |
"/* Интерфейсы для эвентов ${1}Event */", | |
"", | |
"abstract class I${1}Event {}", | |
"", | |
"/* Миксины для эвентов ${1}Event */", | |
"", | |
"/// Создание состояний \"в обработке\"", | |
"mixin _ProcessingStateEmitter on ${1}Event {", | |
" /// Создание состояния \"в обработке\"", | |
" ${1}State inProgress({", | |
" required final ${1}State state,", | |
" final String? message,", | |
" }) =>", | |
" ${1}State.processing(", | |
" data: state.data,", | |
" message: message ?? 'Processing',", | |
" );", | |
"}", | |
"", | |
"/// Выпуск состояния успешной обработки", | |
"mixin _SuccessfulStateEmitter on ${1}Event {", | |
" /// Выпуск состояния успешной обработки", | |
" ${1}State successful({", | |
" required final ${1}State state,", | |
" final ${1}Entity? newData,", | |
" final String? message,", | |
" }) =>", | |
" ${1}State.successful(", | |
" data: newData ?? state.data,", | |
" message: message ?? 'Successful',", | |
" );", | |
"}", | |
"", | |
"/// Выпуск состояния ошибки", | |
"mixin _ErrorStateEmitter on ${1}Event {", | |
" /// Произошла ошибка", | |
" ${1}State error({", | |
" required final ${1}State state,", | |
" final String? message,", | |
" }) =>", | |
" ${1}State.error(", | |
" data: state.data,", | |
" message: message ?? 'An error has occurred',", | |
" );", | |
"}", | |
"", | |
"/// Состояние ожидания действий пользователя", | |
"mixin _IdleStateEmitter on ${1}Event {", | |
" /// Состояние ожидания действий пользователя", | |
" /// Простаиваем до получения события", | |
" ${1}State idle({", | |
" required final ${1}State state,", | |
" final String? message,", | |
" }) =>", | |
" ${1}State.idle(", | |
" data: state.data,", | |
" message: message ?? 'Idle',", | |
" );", | |
"}" | |
] | |
}, | |
"BLoC Test": { | |
"scope": "flutter, dart", | |
"prefix": "blocTest", | |
"description": "Buisness Logic Component Test", | |
"body": [ | |
"blocTest<${1:${TM_FILENAME_BASE/(^[a-zA-Z]{1})(.*)(bloc)/${1:/upcase}${2:/camelcase}/g}}BLoC, ${1}State>(", | |
" '${1}BLoC',", | |
" setUp: () async {},", | |
" tearDown: null,", | |
" build: () => ${1}BLoC(),", | |
" seed: () => ${1}State.idle(),", | |
" act: (bloc) => bloc.add(${1}Event.event()),", | |
" wait: const Duration(milliseconds: 150),", | |
" skip: 0,", | |
" expect: () => <Object>[", | |
" ${1}State.processing(),", | |
" ${1}State.idle(),", | |
" ],", | |
" verify: null,", | |
" errors: null,", | |
");" | |
] | |
}, | |
"Freezed": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"freezed", | |
"freezed_v1" | |
], | |
"description": "Freezed data class", | |
"body": [ | |
"// ignore_for_file: invalid_annotation_target", | |
"", | |
"import 'package:freezed_annotation/freezed_annotation.dart';", | |
"", | |
"part '${TM_FILENAME_BASE}.freezed.dart';", | |
"part '${TM_FILENAME_BASE}.g.dart';", | |
"", | |
"/// ${1} data class", | |
"@Freezed(unionKey: 'type', unionValueCase: FreezedUnionCase.snake)", | |
"class ${1:${TM_FILENAME_BASE/(^[a-zA-Z]{1})(.*)/${1:/upcase}${2:/camelcase}/g}} with _$${1} {", | |
" const ${1}._();", | |
"", | |
" /// Other${1}", | |
" @FreezedUnionValue('OTHER')", | |
" const factory ${1}.other({", | |
" @JsonKey(name: 'value', required: true, disallowNullValue: true)", | |
" required final String value,", | |
" }) = Other${1};", | |
" ${0}", | |
" /// Generate ${1} class from Map<String, Object?>", | |
" factory ${1}.fromJson(Map<String, Object?> json) => _$${1}FromJson(json);", | |
"}" | |
] | |
}, | |
"JSON": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"json", | |
"fromJson", | |
"toJson" | |
], | |
"description": "Generate JSON", | |
"body": [ | |
"/// Generate Class from Map<String, Object?>", | |
"factory ${1:${TM_FILENAME_BASE/(^[a-zA-Z]{1})(.*)/${1:/upcase}${2:/camelcase}/g}}.fromJson(Map<String, Object?> json) => _$${1}FromJson(json);", | |
"", | |
"/// Generate Map<String, Object?> from class", | |
"Map<String, Object?> toJson() => _$${1}ToJson(this);" | |
] | |
}, | |
"Fake": { | |
"scope": "flutter, dart", | |
"prefix": "fake", | |
"description": "Generate Fake class", | |
"body": [ | |
"class Mock${1:${TM_FILENAME_BASE/(^[a-zA-Z]{1})(.*)/${1:/upcase}${2:/camelcase}/g}} extends Fake implements ${1} {}" | |
] | |
}, | |
"Singleton": { | |
"scope": "flutter, dart", | |
"prefix": "singleton", | |
"description": "Generate Fake class", | |
"body": [ | |
"/// ${1} Singleton class", | |
"class ${1:${TM_FILENAME_BASE/(^[a-zA-Z]{1})(.*)/${1:/upcase}${2:/camelcase}/g}} {", | |
" static final ${1} _internalSingleton = ${1}._internal();", | |
" factory ${1}() => _internalSingleton;", | |
" ${1}._internal();\n", | |
" ${0}", | |
"}" | |
] | |
}, | |
"Transformers": { | |
"scope": "flutter, dart", | |
"prefix": "transformer", | |
"description": "StreamTransformer", | |
"body": [ | |
"@immutable", | |
"class ${1:${TM_FILENAME_BASE/(^[a-zA-Z]{1})(.*)/${1:/upcase}${2:/camelcase}/g}}StreamTransformer<${2}, ${3}> extends StreamTransformerBase<${2}, ${3}> {", | |
"", | |
" const ${1}StreamTransformer();", | |
"", | |
" @override", | |
" Stream<${3}> bind(Stream<${2}> stream) {", | |
" StreamSubscription<${2}>? sub;", | |
" final sc = stream.isBroadcast", | |
" ? StreamController<${3}>.broadcast(", | |
" onCancel: () => sub?.cancel(),", | |
" sync: false,", | |
" )", | |
" : StreamController<${3}>(", | |
" onCancel: () => sub?.cancel(),", | |
" sync: false,", | |
" );", | |
" sub = stream.listen((value) {", | |
" ${0}", | |
" sc.add(value as ${3});", | |
" },", | |
" onDone: sc.close,", | |
" onError: sc.addError,", | |
" cancelOnError: false,", | |
" );", | |
" return sc.stream;", | |
" }", | |
"}", | |
"", | |
"/// sourceStream.${1/(.)(.*)/${1:/downcase}$2/g}<${3}>()", | |
"extension ${1}Extensions<${2}> on Stream<${2}> {", | |
" Stream<${3}> ${1/(.)(.*)/${1:/downcase}$2/g}<${3}>() =>", | |
" transform<${3}>(${1}StreamTransformer<${2}, ${3}>());", | |
"}" | |
] | |
}, | |
"MIT License": { | |
"scope": "flutter, dart", | |
"prefix": "mit", | |
"description": "MIT License", | |
"body": [ | |
"/*", | |
" * MIT License", | |
" *", | |
" * Copyright (c) ${CURRENT_YEAR} Matiunin Mikhail <[email protected]>", | |
" *", | |
" * Permission is hereby granted, free of charge, to any person obtaining a copy", | |
" * of this software and associated documentation files (the \"Software\"), to deal", | |
" * in the Software without restriction, including without limitation the rights", | |
" * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell", | |
" * copies of the Software, and to permit persons to whom the Software is", | |
" * furnished to do so, subject to the following conditions:", | |
" *", | |
" * The above copyright notice and this permission notice shall be included in", | |
" * all copies or substantial portions of the Software.", | |
" * ", | |
" * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", | |
" * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", | |
" * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", | |
" * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", | |
" * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", | |
" * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", | |
" * SOFTWARE.", | |
" */\n" | |
] | |
}, | |
"No Such Method": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"nosm", | |
"noSuchMethod" | |
], | |
"description": "This method is invoked when a non-existent method or property is accessed.", | |
"body": [ | |
"@override", | |
"dynamic noSuchMethod(Invocation invocation) {", | |
" ${1:}", | |
"}" | |
] | |
}, | |
"toString": { | |
"scope": "flutter, dart", | |
"prefix": "toString", | |
"description": "Returns a string representation of this object.", | |
"body": [ | |
"@override", | |
"String toString() => ${1:Error.safeToString(this)};${0}" | |
] | |
}, | |
"Test": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"test", | |
"unitTest", | |
"f-test" | |
], | |
"body": [ | |
"test(", | |
" \"${1:test description}\",", | |
" () {", | |
" ${0}", | |
" },", | |
");" | |
], | |
"description": "Create a test function" | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Stateless Widget": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"stl", | |
"statelessWidget" | |
], | |
"description": "Snippet for Stateless Widget", | |
"body": [ | |
"import 'package:flutter/material.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} widget", | |
"/// {@endtemplate}", | |
"class $1 extends StatelessWidget {", | |
" /// {@macro $TM_FILENAME_BASE.$2}", | |
" const $1({", | |
" Key? key,", | |
" }) : super(key: key);", | |
" ", | |
" @override", | |
" Widget build(BuildContext context) =>", | |
" const Placeholder();${0}", | |
"} // $1\n" | |
] | |
}, | |
"Stateless Widget with child": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"stlChild", | |
"statelessWidgetWithChild" | |
], | |
"description": "Snippet for Stateless Widget with child", | |
"body": [ | |
"import 'package:flutter/material.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} widget", | |
"/// {@endtemplate}", | |
"class $1 extends StatelessWidget {", | |
" /// {@macro $TM_FILENAME_BASE.$2}", | |
" const $1({", | |
" required this.child,", | |
" Key? key,", | |
" }) : super(key: key);", | |
" ", | |
" /// The widget below this widget in the tree.", | |
" final Widget child;", | |
" ", | |
" @override", | |
" Widget build(BuildContext context) =>", | |
" child;${0}", | |
"} // $1\n" | |
] | |
}, | |
"Stateful Widget": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"stf", | |
"statefulWidget" | |
], | |
"description": "Snippet for Stateful Widget", | |
"body": [ | |
"import 'package:flutter/material.dart';", | |
"import 'package:meta/meta.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} widget", | |
"/// {@endtemplate}", | |
"class ${1} extends StatefulWidget {", | |
" /// {@macro $TM_FILENAME_BASE.$2}", | |
" const ${1}({", | |
" Key? key,", | |
" }) : super(key: key);", | |
" ", | |
" /// The state from the closest instance of this class", | |
" /// that encloses the given context, if any.", | |
" @internal", | |
" static _${1}State? maybeOf(BuildContext context) =>", | |
" context.findAncestorStateOfType<_${1}State>();", | |
" ", | |
" @override", | |
" State<${1}> createState() => _${1}State();", | |
"} // $1", | |
"", | |
"/// State for widget ${1}", | |
"class _${1}State extends State<${1}> {", | |
"", | |
" /* #region Lifecycle */", | |
" @override", | |
" void initState() {", | |
" super.initState();", | |
" // Initial state initialization", | |
" }", | |
" ", | |
" @override", | |
" void didUpdateWidget(${1} oldWidget) {", | |
" super.didUpdateWidget(oldWidget);", | |
" // Widget configuration changed", | |
" }", | |
" ", | |
" @override", | |
" void didChangeDependencies() {", | |
" super.didChangeDependencies();", | |
" // The configuration of InheritedWidgets has changed", | |
" // Also called after initState but before build", | |
" }", | |
" ", | |
" @override", | |
" void dispose() {", | |
" // Permanent removal of a tree stent", | |
" super.dispose();", | |
" }", | |
" /* #endregion */", | |
" ", | |
" @override", | |
" Widget build(BuildContext context) =>", | |
" const Placeholder();${0}", | |
"} // _${1}State\n" | |
] | |
}, | |
"Stateful Widget with child": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"stfChild", | |
"statefulfWithChild" | |
], | |
"description": "Snippet for Stateful Widget with child", | |
"body": [ | |
"import 'package:flutter/material.dart';", | |
"import 'package:meta/meta.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} widget", | |
"/// {@endtemplate}", | |
"class ${1} extends StatefulWidget {", | |
" /// {@macro $TM_FILENAME_BASE.$2}", | |
" const $1({", | |
" required this.child,", | |
" Key? key,", | |
" }) : super(key: key);", | |
" ", | |
" /// The widget below this widget in the tree.", | |
" final Widget child;", | |
" ", | |
" /// The state from the closest instance of this class", | |
" /// that encloses the given context, if any.", | |
" static ${1}Controller? maybeOf(BuildContext context) =>", | |
" context.findAncestorStateOfType<_${1}State>();", | |
" ", | |
" @override", | |
" State<${1}> createState() => _${1}State();", | |
"} // $1", | |
"", | |
"/// State for widget ${1}", | |
"class _${1}State extends State<${1}> with ${1}Controller {", | |
"", | |
" /* #region Lifecycle */", | |
" @override", | |
" void initState() {", | |
" super.initState();", | |
" // Initial state initialization", | |
" }", | |
" ", | |
" @override", | |
" void didUpdateWidget(${1} oldWidget) {", | |
" super.didUpdateWidget(oldWidget);", | |
" // Widget configuration changed", | |
" }", | |
" ", | |
" @override", | |
" void didChangeDependencies() {", | |
" super.didChangeDependencies();", | |
" // The configuration of InheritedWidgets has changed", | |
" // Also called after initState but before build", | |
" }", | |
" ", | |
" @override", | |
" void dispose() {", | |
" // Permanent removal of a tree stent", | |
" super.dispose();", | |
" }", | |
" /* #endregion */", | |
" ", | |
" @override", | |
" Widget build(BuildContext context) =>", | |
" widget.child;", | |
"} // _${1}State\n", | |
"/// Controller for widget ${1}", | |
"mixin ${1}Controller {", | |
" ${0}", | |
"} // ${1}Controller\n", | |
] | |
}, | |
"Stateful Widget with animation": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"stfAnim", | |
"statefulfAnimation", | |
"singleTickerProviderStateMixin", | |
"animation" | |
], | |
"description": "Snippet for Stateful Widget with animation", | |
"body": [ | |
"import 'package:flutter/material.dart';", | |
"import 'package:meta/meta.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} widget", | |
"/// {@endtemplate}", | |
"class ${1} extends StatefulWidget {", | |
" /// {@macro $TM_FILENAME_BASE.$2}", | |
" const $1({", | |
" required this.child,", | |
" this.duration = const Duration(milliseconds: 250),", | |
" Key? key,", | |
" }) : super(key: key);", | |
" ", | |
" /// The widget below this widget in the tree.", | |
" final Widget child;", | |
" ", | |
" /// The duration of the animation.", | |
" final Duration duration;", | |
" ", | |
" /// The state from the closest instance of this class", | |
" /// that encloses the given context, if any.", | |
" static ${1}Controller? maybeOf(BuildContext context) =>", | |
" context.findAncestorStateOfType<_${1}State>();", | |
" ", | |
" @override", | |
" State<${1}> createState() => _${1}State();", | |
"} // $1", | |
"", | |
"/// State for widget ${1}", | |
"class _${1}State extends State<${1}> with", | |
" SingleTickerProviderStateMixin, ${1}Controller {", | |
"", | |
" late AnimationController _controller;", | |
"", | |
" /* #region Lifecycle */", | |
" @override", | |
" void initState() {", | |
" super.initState();", | |
" _controller = AnimationController(", | |
" vsync: this,", | |
" duration: widget.duration,", | |
" value: 0,", | |
" );", | |
" }", | |
" ", | |
" @override", | |
" void didUpdateWidget(${1} oldWidget) {", | |
" super.didUpdateWidget(oldWidget);", | |
" if (widget.duration != _controller.duration) {", | |
" _controller.duration = widget.duration;", | |
" }", | |
" }", | |
" ", | |
" @override", | |
" void didChangeDependencies() {", | |
" super.didChangeDependencies();", | |
" // The configuration of InheritedWidgets has changed", | |
" // Also called after initState but before build", | |
" }", | |
" ", | |
" @override", | |
" void dispose() {", | |
" _controller.dispose();", | |
" super.dispose();", | |
" }", | |
" /* #endregion */", | |
" ", | |
" Future<void> forward() async {", | |
" if (_controller.isCompleted) return;", | |
" try {", | |
" await _controller.forward().orCancel;", | |
" } on TickerCanceled {", | |
" // the animation got canceled, probably because we were disposed", | |
" }", | |
" }", | |
" ", | |
" Future<void> reverse() async {", | |
" if (_controller.isDismissed) return;", | |
" try {", | |
" await _controller.reverse().orCancel;", | |
" } on TickerCanceled {", | |
" // the animation got canceled, probably because we were disposed", | |
" }", | |
" }", | |
" ", | |
" @override", | |
" Widget build(BuildContext context) =>", | |
" widget.child;", | |
"} // _${1}State\n", | |
"/// Controller for widget ${1}", | |
"mixin ${1}Controller {", | |
" ${0}", | |
"} // ${1}Controller\n", | |
] | |
}, | |
"Inherited Widget": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"inh", | |
"inheritedWidget" | |
], | |
"description": "Inherited Widget", | |
"body": [ | |
"import 'package:flutter/material.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} widget", | |
"/// {@endtemplate}", | |
"class ${1} extends InheritedWidget {", | |
" /// {@macro $TM_FILENAME_BASE.$2}", | |
" const ${1}({", | |
" required Widget child,", | |
" Key? key,", | |
" }) : super(key: key, child: child);", | |
" ", | |
" @override", | |
" bool updateShouldNotify(${1} oldWidget) =>", | |
" false;${0}", | |
"} // ${1}\n" | |
] | |
}, | |
"Inherited Notifier": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"inhNotifier", | |
"inheritedNotifier" | |
], | |
"description": "Inherited Notifier", | |
"body": [ | |
"import 'package:flutter/material.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} widget", | |
"/// {@endtemplate}", | |
"class ${1} extends InheritedNotifier<ValueListenable<${2:int}>> {", | |
" /// {@macro $TM_FILENAME_BASE.$2}", | |
" const ${1}({", | |
" required Widget child,", | |
" required ValueListenable<${2:int}> notifier,", | |
" Key? key,", | |
" }) : super(key: key, child: child, notifier: notifier);", | |
" ", | |
" @override", | |
" bool updateShouldNotify(${1} oldWidget) =>", | |
" false;${0}", | |
"} // ${1}\n" | |
] | |
}, | |
"Inherited Model": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"inhModel", | |
"inheritedModel" | |
], | |
"description": "Inherited Model", | |
"body": [ | |
"import 'package:collection/collection.dart';", | |
"import 'package:flutter/foundation.dart';", | |
"import 'package:flutter/material.dart';\n\n", | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}} widget", | |
"/// {@endtemplate}", | |
"class ${1} extends InheritedModel<int> {", | |
" /// {@macro ${1}.${1}}", | |
" const ${1}({", | |
" required Widget child,", | |
" required this.values,", | |
" Key? key,", | |
" }) : super(key: key, child: child);", | |
"", | |
" final List<${2:Entity}> values;", | |
"", | |
" static ${2}? getById(BuildContext context, int id) =>", | |
" InheritedModel.inheritFrom<${1}>(context, aspect: id)", | |
" ?.values", | |
" .firstWhereOrNull((e) => e.id == id);", | |
"", | |
" @override", | |
" bool updateShouldNotify(${1} oldWidget) =>", | |
" !listEquals(values, oldWidget.values);", | |
"", | |
" @override", | |
" bool updateShouldNotifyDependent(${1} oldWidget, Set<int> aspects) {", | |
" for (final id in aspects) {", | |
" if (values.firstWhereOrNull((e) => e.id == id) ==", | |
" oldWidget.values.firstWhereOrNull((e) => e.id == id)) return true;", | |
" }", | |
" return false;", | |
" }", | |
"} // ${1}\n" | |
] | |
}, | |
"Build Method": { | |
"scope": "flutter, dart", | |
"prefix": "build", | |
"description": "Describes the part of the user interface represented by this widget.", | |
"body": [ | |
"@override", | |
"Widget build(BuildContext context) =>", | |
" ${0};" | |
] | |
}, | |
"Notification Listener": { | |
"scope": "flutter, dart", | |
"prefix": "notificationListener", | |
"description": "Notification Listener", | |
"body": [ | |
"NotificationListener<${1}>(", | |
" onNotification: (notification) {", | |
" // ...", | |
" // Return true to cancel the notification bubbling", | |
" return true;", | |
" },", | |
" child: child,${0}", | |
")," | |
] | |
}, | |
"Custom Painter": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"painter", | |
"customPainter" | |
], | |
"description": "Used for creating custom paint", | |
"body": [ | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}}Painter", | |
"/// {@endtemplate}", | |
"class ${1}Painter extends CustomPainter {", | |
"", | |
" const ${1}Painter({Listenable? repaint}) : super(repaint: repaint);", | |
"", | |
" @override", | |
" void paint(Canvas canvas, Size size) {", | |
" ${0}", | |
" }", | |
"", | |
" @override", | |
" bool shouldRepaint(${1}Painter oldDelegate) => false;", | |
"", | |
" @override", | |
" bool shouldRebuildSemantics(${1}Painter oldDelegate) => false;", | |
"} // ${1}\n" | |
] | |
}, | |
"Custom Clipper ": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"clipper", | |
"customClipper" | |
], | |
"description": "Used for creating custom shapes", | |
"body": [ | |
"/// {@template $TM_FILENAME_BASE.${2:$TM_FILENAME_BASE}}", | |
"/// ${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}}Painter", | |
"/// {@endtemplate}", | |
"class ${1}Clipper extends CustomClipper<Path> {", | |
"", | |
" const ${1}Clipper({Listenable? reclip}) : super(reclip: reclip);", | |
"", | |
" @override", | |
" Path getClip(Size size) {", | |
" ${0}", | |
" }", | |
"", | |
" @override", | |
" bool shouldReclip(${1}Clipper oldClipper) => false;", | |
"} // ${1}\n" | |
] | |
}, | |
"of": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"of", | |
"maybeOf" | |
], | |
"description": "InheritedWidget.of(BuildContext)", | |
"body": [ | |
"/// The state from the closest instance of this class", | |
"/// that encloses the given context, if any.", | |
"/// e.g. `${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}}.maybeOf(context)`", | |
"static ${1}? maybeOf(BuildContext context, {bool listen = true}) {", | |
" if (listen) {", | |
" return context.dependOnInheritedWidgetOfExactType<${1}>();", | |
" } else {", | |
" final inhW = context.getElementForInheritedWidgetOfExactType<${1}>()?.widget;", | |
" return inhW is ${1} ? inhW : null;", | |
" }", | |
"}", | |
"", | |
"static Never _notFoundInheritedWidgetOfExactType() =>", | |
" throw ArgumentError(", | |
" 'Out of scope, not found inherited widget '", | |
" 'a ${1} of the exact type',", | |
" 'out_of_scope',", | |
" );", | |
"", | |
"/// The state from the closest instance of this class", | |
"/// that encloses the given context.", | |
"/// e.g. `${1}.of(context)`", | |
"static ${1}? of(BuildContext context, {bool listen = true}) =>", | |
" maybeOf(context, listen: listen) ?? _notFoundInheritedWidgetOfExactType();${0}\n" | |
] | |
}, | |
"stateOf": { | |
"scope": "flutter, dart", | |
"prefix": "stateOf", | |
"description": "InheritedWidget.of(BuildContext)", | |
"body": [ | |
"/// The state from the closest instance of this class", | |
"/// that encloses the given context, if any.", | |
"/// e.g. `${1:${TM_FILENAME_BASE/(.)(.*)/${1:/upcase}${2:/camelcase}/}State}.maybeOf(context)`", | |
"static ${1}? maybeOf(BuildContext context) =>", | |
" context.findAncestorStateOfType<${1}>();", | |
"", | |
"static Never _notFoundStateOfType() =>", | |
" throw ArgumentError(", | |
" 'Out of scope, not found state of type ${1}',", | |
" 'out_of_scope',", | |
" );", | |
"", | |
"/// The state from the closest instance of this class", | |
"/// that encloses the given context.", | |
"/// e.g. `${1}.of(context)`", | |
"static ${1}? of(BuildContext context) =>", | |
" maybeOf(context) ?? _notFoundStateOfType();${0}\n" | |
] | |
}, | |
"debugFillProperties": { | |
"scope": "flutter, dart", | |
"prefix": "debugFillProperties", | |
"description": "debugFillProperties", | |
"body": [ | |
"@override", | |
"void debugFillProperties(DiagnosticPropertiesBuilder properties) =>", | |
" super.debugFillProperties(", | |
" properties", | |
" ..add(", | |
" StringProperty(", | |
" 'description',", | |
" 'description',", | |
" ),", | |
" ),", | |
" );", | |
"" | |
] | |
}, | |
"InitState ": { | |
"scope": "flutter, dart", | |
"prefix": "initS", | |
"body": [ | |
"@override", | |
"void initState() {", | |
" super.initState();", | |
" ${0:}", | |
"}" | |
], | |
"description": "Called when this object is inserted into the tree. The framework will call this method exactly once for each State object it creates." | |
}, | |
"Dispose": { | |
"scope": "flutter, dart", | |
"prefix": "dis", | |
"body": [ | |
"@override", | |
"void dispose() {", | |
" ${0:}", | |
" super.dispose();", | |
"}" | |
], | |
"description": "Called when this object is removed from the tree permanently. The framework calls this method when this State object will never build again." | |
}, | |
"Reassemble": { | |
"scope": "flutter, dart", | |
"prefix": "reassemble", | |
"body": [ | |
"@override", | |
"void reassemble(){", | |
" super.reassemble();", | |
" ${0:}", | |
"}" | |
], | |
"description": "Called whenever the application is reassembled during debugging, for example during hot reload." | |
}, | |
"didChangeDependencies": { | |
"scope": "flutter, dart", | |
"prefix": "didChangeD", | |
"body": [ | |
"@override", | |
"void didChangeDependencies() {", | |
" super.didChangeDependencies();", | |
" ${0:}", | |
"}" | |
], | |
"description": "Called when a dependency of this State object changes" | |
}, | |
"didUpdateWidget": { | |
"scope": "flutter, dart", | |
"prefix": "didUpdateW", | |
"body": [ | |
"@override", | |
"void didUpdateWidget (${1:Type} ${2:oldWidget}) {", | |
" super.didUpdateWidget(${2:oldWidget});", | |
" ${0:}", | |
"}" | |
], | |
"description": "Called whenever the widget configuration changes." | |
}, | |
"ListView.Builder": { | |
"scope": "flutter, dart", | |
"prefix": "listViewB", | |
"body": [ | |
"ListView.builder(", | |
" itemCount: ${1:1},", | |
" itemBuilder: (BuildContext context, int index) {", | |
" return ${2:};", | |
" },", | |
")," | |
], | |
"description": "Creates a scrollable, linear array of widgets that are created on demand.Providing a non-null `itemCount` improves the ability of the [ListView] to estimate the maximum scroll extent." | |
}, | |
"ListView.Separated": { | |
"scope": "flutter, dart", | |
"prefix": "listViewS", | |
"body": [ | |
"ListView.separated(", | |
" itemCount: ${1:1},", | |
" separatorBuilder: (BuildContext context, int index) {", | |
" return ${2:};", | |
" },", | |
" itemBuilder: (BuildContext context, int index) {", | |
" return ${3:};", | |
" },", | |
")," | |
], | |
"description": "Creates a fixed-length scrollable linear array of list 'items' separated by list item 'separators'." | |
}, | |
"GridView.Builder": { | |
"scope": "flutter, dart", | |
"prefix": "gridViewB", | |
"body": [ | |
"GridView.builder(", | |
" gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(", | |
" crossAxisCount: ${1:2},", | |
" ),", | |
" itemCount: ${2:2},", | |
" itemBuilder: (BuildContext context, int index) {", | |
" return ${3:};", | |
" },", | |
")," | |
], | |
"description": "Creates a scrollable, 2D array of widgets that are created on demand. Providing a non-null `itemCount` improves the ability of the [GridView] to estimate the maximum scroll extent." | |
}, | |
"GridView.Count": { | |
"scope": "flutter, dart", | |
"prefix": "gridViewC", | |
"body": [ | |
"GridView.count(", | |
" crossAxisSpacing: ${1:1},", | |
" mainAxisSpacing: ${2:2},", | |
" crossAxisCount: ${3:2},", | |
" children: <Widget> [", | |
" ${4:}", | |
" ],", | |
")," | |
], | |
"description": "Creates a scrollable, 2D array of widgets with a fixed number of tiles in the cross axis." | |
}, | |
"GridView.Extent": { | |
"scope": "flutter, dart", | |
"prefix": "gridViewE", | |
"body": [ | |
"GridView.extent(", | |
" maxCrossAxisExtent: ${1:2},", | |
" children: <Widget> [", | |
" ${2:}", | |
" ],", | |
")," | |
], | |
"description": "Creates a scrollable, 2D array of widgets with tiles that each have a maximum cross-axis extent." | |
}, | |
"Custom Scroll View": { | |
"scope": "flutter, dart", | |
"prefix": "customScrollV", | |
"body": [ | |
"CustomScrollView(", | |
" slivers: <Widget>[", | |
" ${0:}", | |
" ],", | |
")," | |
], | |
"description": "Creates a `ScrollView` that creates custom scroll effects using slivers. If the `primary` argument is true, the `controller` must be null." | |
}, | |
"Stream Builder": { | |
"scope": "flutter, dart", | |
"prefix": "streamBldr", | |
"body": [ | |
"StreamBuilder<${1:int}>(", | |
" initialData: ${2:initialData},", | |
" stream: ${3:stream},", | |
" builder: (context, snapshot) {", | |
" return const Placeholder();", | |
" },", | |
")," | |
], | |
"description": "Creates a new `StreamBuilder` that builds itself based on the latest snapshot of interaction with the specified `stream`" | |
}, | |
"Animated Builder": { | |
"scope": "flutter, dart", | |
"prefix": "animatedBldr", | |
"body": [ | |
"AnimatedBuilder(", | |
" animation: ${1:animation},", | |
" builder: (context, child) =>", | |
" ${2:const Placeholder()},", | |
" child: ${3:child},", | |
")," | |
], | |
"description": "Creates an Animated Builder. The widget specified to `child` is passed to the `builder`" | |
}, | |
"Value Listenable Builder": { | |
"scope": "flutter, dart", | |
"prefix": "valueListenableBuilder", | |
"description": "Given a ValueListenable<T> and a builder which builds widgets from concrete values of T, this class will automatically register itself as a listener of the ValueListenable and call the builder with updated values when the value changes.", | |
"body": [ | |
"ValueListenableBuilder<${1:int}>(", | |
" valueListenable: ${2: null},", | |
" builder: (context, value, child) =>", | |
" ${2:const Placeholder()},", | |
" child: ${3:child},", | |
")," | |
] | |
}, | |
"Stateful Builder": { | |
"scope": "flutter, dart", | |
"prefix": "statefulBldr", | |
"body": [ | |
"StatefulBuilder(", | |
" builder: (BuildContext context, setState) {", | |
" return ${0:};", | |
" },", | |
")," | |
], | |
"description": "Creates a widget that both has state and delegates its build to a callback. Useful for rebuilding specific sections of the widget tree." | |
}, | |
"Orientation Builder": { | |
"scope": "flutter, dart", | |
"prefix": "orientationBldr", | |
"body": [ | |
"OrientationBuilder(", | |
" builder: (BuildContext context, Orientation orientation) {", | |
" return Container(", | |
" child: ${3:child},", | |
" );", | |
" },", | |
")," | |
], | |
"description": "Creates a builder which allows for the orientation of the device to be specified and referenced" | |
}, | |
"Layout Builder": { | |
"scope": "flutter, dart", | |
"prefix": "layoutBldr", | |
"body": [ | |
"LayoutBuilder(", | |
" builder: (BuildContext context, BoxConstraints constraints) {", | |
" return ${0:};", | |
" },", | |
")," | |
], | |
"description": "Similar to the Builder widget except that the framework calls the builder function at layout time and provides the parent widget's constraints." | |
}, | |
"Single Child ScrollView": { | |
"scope": "flutter, dart", | |
"prefix": "singleChildSV", | |
"body": [ | |
"SingleChildScrollView(", | |
" controller: ${1:controller,}", | |
" child: Column(", | |
" ${0:}", | |
" ),", | |
")," | |
], | |
"description": "Creates a scroll view with a single child" | |
}, | |
"Future Builder": { | |
"scope": "flutter, dart", | |
"prefix": "futureBldr", | |
"body": [ | |
"FutureBuilder(", | |
" future: ${1:Future},", | |
" initialData: ${2:InitialData},", | |
" builder: (BuildContext context, AsyncSnapshot snapshot) {", | |
" return ${3:};", | |
" },", | |
")," | |
], | |
"description": "Creates a Future Builder. This builds itself based on the latest snapshot of interaction with a Future." | |
}, | |
"debugPrint": { | |
"scope": "flutter, dart", | |
"prefix": "debugP", | |
"description": "Prints a message to the console, which you can access using the flutter tool's `logs` command (flutter logs).", | |
"body": [ | |
"debugPrint(${1:statement});" | |
] | |
}, | |
"Material App": { | |
"scope": "flutter, dart", | |
"prefix": "mateapp", | |
"description": "Create a MaterialApp", | |
"body": [ | |
"import 'package:flutter/material.dart';", | |
"", | |
"void main() => runApp(const MyApp());", | |
"", | |
"class MyApp extends StatelessWidget {", | |
" const MyApp({Key? key}) : super(key: key);", | |
"", | |
" @override", | |
" Widget build(BuildContext context) {", | |
" return MaterialApp(", | |
" title: 'Material App',", | |
" home: Scaffold(", | |
" appBar: AppBar(", | |
" title: const Text('Material App Bar'),", | |
" ),", | |
" body: const Center(", | |
" child: Text('Hello World'),", | |
" ),", | |
" ),", | |
" );", | |
" }", | |
"}" | |
] | |
}, | |
"Cupertino App": { | |
"scope": "flutter, dart", | |
"prefix": "cupeapp", | |
"description": "Create a CupertinoApp", | |
"body": [ | |
"import 'package:flutter/cupertino.dart';", | |
"", | |
"void main() => runApp(const MyApp());", | |
"", | |
"class MyApp extends StatelessWidget {", | |
" const MyApp({Key? key}) : super(key: key);", | |
"", | |
" @override", | |
" Widget build(BuildContext context) {", | |
" return const CupertinoApp(", | |
" title: 'Cupertino App',", | |
" home: CupertinoPageScaffold(", | |
" navigationBar: CupertinoNavigationBar(", | |
" middle: Text('Cupertino App Bar'),", | |
" ),", | |
" child: Center(", | |
" child: Text('Hello World'),", | |
" ),", | |
" ),", | |
" );", | |
" }", | |
"}" | |
] | |
}, | |
"Tween Animation Builder": { | |
"scope": "flutter, dart", | |
"prefix": "tweenAnimationBuilder", | |
"body": [ | |
"TweenAnimationBuilder(", | |
" duration: ${1:const Duration(),}", | |
" tween: ${2:Tween(),}", | |
" builder: (BuildContext context, ${3:dynamic} value, Widget? child) {", | |
" return ${4:Container();}", | |
" },", | |
")," | |
], | |
"description": "Widget builder that animates a property of a Widget to a target value whenever the target value changes." | |
}, | |
"Test Widgets": { | |
"scope": "flutter, dart", | |
"prefix": [ | |
"testWidget", | |
"widgetTest", | |
"f-widgetTest" | |
], | |
"body": [ | |
"testWidgets(", | |
" \"${1:test description}\",", | |
" (tester) async {", | |
" ${0}", | |
" },", | |
");" | |
], | |
"description": "Create a testWidgets function" | |
}, | |
"Material Package": { | |
"scope": "flutter, dart", | |
"prefix": "import_material", | |
"body": "import 'package:flutter/material.dart';", | |
"description": "Import flutter material package" | |
}, | |
"Cupertino Package": { | |
"scope": "flutter, dart", | |
"prefix": "import_cupertino", | |
"body": "import 'package:flutter/cupertino.dart';", | |
"description": "Import Flutter Cupertino package" | |
}, | |
"flutter_test Package": { | |
"scope": "flutter, dart", | |
"prefix": "import_flutter_test", | |
"body": "import 'package:flutter_test/flutter_test.dart';", | |
"description": "Import flutter_test package" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Visual Studio Code snippets guide