-
-
Save FilledStacks/b57b77da10fdcb2d4d95a28de4a4ced4 to your computer and use it in GitHub Desktop.
{ | |
"Freezed model": { | |
"prefix": "frz", | |
"body": [ | |
"@freezed", | |
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}} with _$${1} {", | |
" factory ${1}({", | |
" required ${2:String id},", | |
" }) = _${1};", | |
"}" | |
], | |
"description": "Freezed model" | |
}, | |
"Freezed model Json": { | |
"prefix": "frzjs", | |
"body": [ | |
"@freezed", | |
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}} with _$${1} {", | |
" factory ${1}({", | |
" required ${2:String id},", | |
" }) = _${1};", | |
"", | |
"factory ${1}.fromJson(Map<String, dynamic> json) => ", | |
"_$${1}FromJson(json);", | |
"}" | |
], | |
"description": "Freezed model with Json" | |
}, | |
"Freezed New File model": { | |
"prefix": "frzn", | |
"body": [ | |
"import 'package:freezed_annotation/freezed_annotation.dart';", | |
"", | |
"part '${TM_FILENAME_BASE/(.*)/${1:/lowercase}/g}.freezed.dart';", | |
"part '${TM_FILENAME_BASE/(.*)/${1:/lowercase}/g}.g.dart';", | |
"@freezed", | |
"class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}} with _$${1} {", | |
" factory ${1}({", | |
" required ${2:String id},", | |
" }) = _${1};", | |
"", | |
"factory ${1}.fromJson(Map<String, dynamic> json) => ", | |
"_$${1}FromJson(json);", | |
"}" | |
], | |
"description": "Freezed model with Json" | |
}, | |
"Stacked View": { | |
"prefix": "stkv", | |
"body": [ | |
"import 'package:flutter/material.dart';", | |
"import 'package:stacked/stacked.dart';", | |
"", | |
"class ${1} extends StatelessWidget {", | |
" const ${1}({Key? super.key});", | |
"", | |
" @override", | |
" Widget build(BuildContext context) {", | |
" return ViewModelBuilder<${1}Model>.reactive(", | |
" builder: (context, model, child) => Scaffold(),", | |
" viewModelBuilder: () => ${1}Model(),", | |
" );", | |
" }", | |
"}" | |
], | |
"description": "Stacked View" | |
}, | |
"Stacked BaseViewModel": { | |
"prefix": "stkbvm", | |
"body": [ | |
"import 'package:stacked/stacked.dart';", | |
"", | |
"class ${1}Model extends BaseViewModel {}", | |
], | |
"description": "Stacked BaseViewModel" | |
}, | |
"Mock Registration": { | |
"prefix": "testr", | |
"body": [ | |
"Mock${1} getAndRegister${1}() {", | |
" _removeRegistrationIfExists<${1}>();", | |
" final service = Mock${1}();", | |
" locator.registerSingleton<${1}>(service);", | |
" return service;", | |
"}" | |
], | |
"description": "Creating a Mock Registration Function" | |
}, | |
"Core Mock Registration": { | |
"prefix": "testrc", | |
"body": [ | |
"Mock${1} getAndRegister${1}() {", | |
" _removeRegistrationIfExists<${1}>();", | |
" final service = Mock${1}();", | |
" coreLocator.registerSingleton<${1}>(service);", | |
" return service;", | |
"}" | |
], | |
"description": "Creating a Mock Registration for Core Locator" | |
}, | |
"Main Test Suite Setup": { | |
"prefix": "testm", | |
"body": [ | |
"void main() {", | |
" group('${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}} -', (){", | |
"", | |
" });", | |
"}" | |
], | |
"description": "Main Test Suite Setup" | |
}, | |
"Main Test Suite Setup with Services": { | |
"prefix": "testmr", | |
"body": [ | |
"import 'package:flutter_test/flutter_test.dart';", | |
"", | |
"void main() {", | |
" group('${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}} -', (){", | |
" setUp(() => registerServices());", | |
" tearDown(() => unregisterServices());", | |
" });", | |
"}" | |
], | |
"description": "Main Test Suite Setup with Services" | |
}, | |
"Test Group Setup": { | |
"prefix": "testg", | |
"description": "Creates a Test group with a test", | |
"body": [ | |
"group('${1} -', () {", | |
" test('${2}', () {", | |
"", | |
" });", | |
"});", | |
] | |
}, | |
"Single Test Setup": { | |
"prefix": "tests", | |
"description": "Creates a single test", | |
"body": [ | |
" test('${1}', () {", | |
"", | |
" });", | |
] | |
}, | |
} |
Thanks 👍
First, thank you for these snippets, and for everything you've provided to the flourishing world of prospering Flutter developers and aspiring mobile app architects. ⚡👍
Add this in each snippet to make the snippet available only when there is a
dart
orflutter
scope."scope": "dart,flutter",
The scope
property gives me 7 warnings in the VS Code 'Problems' panel: Property scope is not allowed.
I think the scope is only valid if you're adding the snippets globally. If you're adding them to dart.json they're already scoped and you'll get the warning (but they still work).
Is it possible to use this in Android studio?
# line:36: " const ${1}({Key key}) : super(key: key);",
# dart error
# The parameter 'key' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
# Try adding either an explicit non-'null' default value or the 'required' modifier.dart(missing_default_value_for_parameter)
# Does it need to be changed? -> ({ Key? key })
# line:36: " const ${1}({Key key}) : super(key: key);", # dart error # The parameter 'key' can't have a value of 'null' because of its type, but the implicit default value is 'null'. # Try adding either an explicit non-'null' default value or the 'required' modifier.dart(missing_default_value_for_parameter) # Does it need to be changed? -> ({ Key? key })
I think so... also if you have linting option dart(prefer_const_constructors) enabled, you need to change ...
#line:42 => const Scaffold()
awesome snippet!
Please, how do I add this snippet in android studio?
How do I get this to work on IntelliJ IDEA? I think they handle snippets differently.
line:36: " const ${1}({Key key}) : super(key: key);", dart error The parameter 'key' can't have a value of 'null' because of its type, but the implicit default value is 'null'. Try adding either an explicit non-'null' default value or the 'required' modifier.dart(missing_default_value_for_parameter) Does it need to be changed? -> ({ Key? key })
I agree
Updated line:36: " const ${1}({Key key}) : super(key: key);", to ({ Key? key })
@demolaf @djoshua21 @Edamijueda
How to convert these snippets for use in Android Studio
- Create a Dart scratch file (Cmd+Shift+N)
- Paste in the body of any snippet into the scratch file
- Remove the double quotes and extra commas (Cmd+R is the replace command)
- Replace the token placeholders with variable names (${1} =>
$placeholderName$ ) - Highlight the transformed code, and go to Tools > Save as Live Template
- Add the abbreviation and description as seen in the dialog box below
- Make sure to add a default value to each variable used (see the edit variables button on live template dialog below)
- Once saved you can use the stkv template anywhere in the Flutter/Dart scope
For example (transform the body of stkv - line 31 from this)
"import 'package:flutter/material.dart';",
"import 'package:stacked/stacked.dart';",
"",
"class ${1} extends StatelessWidget {",
" const ${1}({Key? key}) : super(key: key);",
"",
" @override",
" Widget build(BuildContext context) {",
" return ViewModelBuilder<${1}Model>.reactive(",
" builder: (context, model, child) => Scaffold(),",
" viewModelBuilder: () => ${1}Model(),",
" );",
" }",
"}"
The translated snippet should look something like this:
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
class $classname$ extends StatelessWidget {
const $classname$({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ViewModelBuilder<$viewName$Model>.reactive(
builder: (context, model, child) => Scaffold(),
viewModelBuilder: () => $viewName$Model(),
);
}
}
Live Template Dialog box
P.S.
Pretty sure this will work for IntelliJ as well since AS is built on top
References
Scratch Files
Android Studio Code Snippets
Editing live templates - IntelliJ
Add this in each snippet to make the snippet available only when there is a
dart
orflutter
scope.