flutter-snippets
By rishiA package for flutter code snippets
Paste this command in a terminal to install the package
espanso install flutter-snippets
matches:
# Sstateless widget
- trigger: ':stlw'
vars:
- name: form
type: form
params:
layout: |
Widget name [[name]]
replace: "import 'package:flutter/material.dart';\n\nclass {{form.name}} extends StatelessWidget {\n\t@override\n\tWidget build(BuildContext context) {\n\t\treturn Container(\n\t\t\tchild: Text('Hello World'),\n\t\t);\n\t}\n}"
# Statefull widget
- trigger: ':stfl'
vars:
- name: form
type: form
params:
layout: |
Widget name [[name]]
replace: "import 'package:flutter/material.dart';\n\nclass {{form.name}} extends StatefulWidget {\n\t@override\n\t_{{form.name}}State createState() => _{{form.name}}State();\n}\n\nclass _{{form.name}}State extends State<{{form.name}}> {\n\t@override\n\tWidget build(BuildContext context) {\n\t\treturn Container(\n\t\t\tchild: Text('Hello World'),\n\t\t);\n\t}\n}"
# Describes the part of the user interface represented by this widget.
- trigger: ':build'
replace: "@override\nWidget build(BuildContext context) {\n\treturn Container(\n\t\tchild: Text('Hello World'),\n\t);\n}"
# Used for creating custom paint.
- trigger: ':customPainter'
vars:
- name: form
type: form
params:
layout: |
Widget name [[name]]
replace: "class {{form.name}}Painter extends CustomPainter {\n\n\t@override\n\tvoid paint(Canvas canvas, Size size) { }\n\t@override\n\tbool shouldRepaint(${0:name}Painter oldDelegate) => false;\n\n\t@override\n\tbool shouldRebuildSemantics(${0:name}Painter oldDelegate) => false;\n}"
# Used for creating custom shapes.
- trigger: ':customClipper'
vars:
- name: form
type: form
params:
layout: |
Widget name [[name]]
replace: "class {{form.name}}Clipper extends CustomClipper<Path> {\n\n\t@override\n\tPath getClip(Size size) { }\n\n\t@override\n\tbool shouldReclip(CustomClipper<Path> oldClipper) => false;\n}"
# Called when this object is inserted into the tree. The framework will call this method exactly once for each State object it creates.
- trigger: ':initS'
replace: "@override\nvoid initState() {\n\t// TODO: Enter your code here\n\tsuper.initState();\n}"
# Called when this object is removed from the tree permanently. The framework calls this method when this State object will never build again.
- trigger: ':dis'
replace: "@override\nvoid dispose() {\n\t// TODO: Enter your code here\n\tsuper.dispose();\n}"
# "Called whenever the application is reassembled during debugging, for example during hot reload.
- trigger: ':reassemble'
replace: "@override\nvoid reassemble() {\n\t// TODO: Enter your code here\n\tsuper.reassemble();\n}"
# "Called when a dependency of this State object changes.
- trigger: ':didChangeD'
replace: "@override\nvoid didChangeDependencies() {\n\t// TODO: Enter your code here\n\tsuper.didChangeDependencies();\n}"
# "Called whenever the widget configuration changes.
- trigger: ':didUpdateW'
vars:
- name: form
type: form
params:
layout: |
Widget type [[type]]
Widgent name [[name]]
replace: "@override\nvoid didUpdateWidget({{form.type}} {{form.name}}) {\n\t// TODO: Enter your code here\n\tsuper.didUpdateWidget({{form.name}});\n}"
# "Import flutter material package.
- trigger: ':importM'
replace: "import 'package:flutter/material.dart';"
# "Import flutter Cupertino package.
- trigger: ':importC'
replace: "import 'package:flutter/cupertino.dart';"