- 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