Skip to content

Commit

Permalink
Merge pull request #19 from rishi-singh26/main
Browse files Browse the repository at this point in the history
New package : flutter-snippets
  • Loading branch information
smeech authored Jun 15, 2024
2 parents 3d16206 + f198492 commit 639a7fc
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 0 deletions.
192 changes: 192 additions & 0 deletions packages/flutter-snippets/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# A package for some commonly used flutter code snippets

Code snippets taken from [awesome-flutter-snippets](https://github.com/Nash0x7E2/awesome-flutter-snippets).

## Installation

Install the package with:

``` shell
espanso install flutter-snippets
```

## Usage

This package replaces the following keywords with the associated code snippet while you're typing:

Keyword | Description
--- | ---
[`:stlw`](#stateless-widget) | Stateless widget
[`:stfl`](#statefull-widget) | Statefull widget
[`:build`](#build-method) | Build method
[`:customPainter`](#custompainter-widget) | Custom Painter widget
[`:customClipper`](#customclipper-widget) | Custom Clipper widget
[`:initS`](#initstate-method) | initState method
[`:disp`](#dispose-method) | dispose method
[`:reassemble`](#reassemble-method) | reassemble method
[`:didChangeD`](#didchangedependencies-method) | didChangeDependencies method
[`:didUpdateW`](#didupdatewidget-method) | didUpdateWidget method
[`:importM`](#import-materialdart) | Import material.dart
[`:importC`](#import-cupertinodart) | Import cupertino.dart

</br>

> ## Stateless widget
>
> ### Keyword => **:stlw**
>
> ```dart
> import 'package:flutter/material.dart';
>
> class Example extends StatelessWidget {
> @override
> Widget build(BuildContext context) {
> return Container(
> child: Text('Hello World'),
> );
> }
> }
> ```
<!-- -->
> ## Statefull widget
>
> ### Keyword => **:stfl**
>
> ```dart
> import 'package:flutter/material.dart';
>
> class Example extends StatefulWidget {
> @override
> _ExampleState createState() =>_ExampleState();
> }
>
> class _ExampleState extends State<Example> {
> @override
> Widget build(BuildContext context) {
> return Container(
> child: Text('Hello World'),
> );
> }
> }
> ```
<!-- -->
> ## Build method
>
> ### Keyword => **:build**
>
> ```dart
> @override
> Widget build(BuildContext context) {
> return Container(
> child: Text('Hello World'),
> );
> }
> ```
<!-- -->
> ## CustomPainter widget
>
> ### Keyword => **:customPainter**
>
> ```dart
> class ExamplePainter extends CustomPainter {
>
> @override
> void paint(Canvas canvas, Size size) { }
> @override
> bool shouldRepaint(${0:name}Painter oldDelegate) => false;
>
> @override
> bool shouldRebuildSemantics(${0:name}Painter oldDelegate) => false;
> }
> ```
<!-- -->
> ## CustomClipper widget
>
> ### Keyword => **:customClipper**
>
> ```dart
> class ExampleClipper extends CustomClipper<Path> {
>
> @override
> Path getClip(Size size) { }
>
> @override
> bool shouldReclip(CustomClipper<Path> oldClipper) => false;
> }
> ```
<!-- -->
> ## initState method
>
> ### Keyword => **:initS**
>
> ```dart
> @override
> void initState() {
> // TODO: Enter your code here
> super.initState();
> }
> ```
<!-- -->
> ## dispose method
>
> ### Keyword => **:disp**
>
> ```dart
> @override
> void dispose() {
> // TODO: Enter your code here
> super.dispose();
> }
> ```
<!-- -->
> ## reassemble method
>
> ### Keyword => **:reassemble**
>
> ```dart
> @override
> void reassemble() {
> // TODO: Enter your code here
> super.reassemble();
> }
> ```
<!-- -->
> ## didChangeDependencies method
>
> ### Keyword => **:didChangeD**
>
> ```dart
> @override
> void didChangeDependencies() {
> // TODO: Enter your code here
> super.didChangeDependencies();
> }
> ```
<!-- -->
> ## didUpdateWidget method
>
> ### Keyword => **:didUpdateW**
>
> ```dart
> @override
> void didUpdateWidget(Widget widget) {
> // TODO: Enter your code here
> super.didUpdateWidget(oldWidget);
> }
> ```
<!-- -->
> ## import material.dart
>
> ### Keyword => **:importM**
>
> ```dart
> import 'package:flutter/material.dart';
> ```
<!-- -->
> ## import cupertino.dart
>
> ### Keyword => **:importC**
>
> ```dart
> import 'package:flutter/cupertino.dart';
> ```
6 changes: 6 additions & 0 deletions packages/flutter-snippets/0.1.0/_manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'flutter-snippets'
title: 'Flutter snippets'
description: A package for flutter code snippets
version: 0.1.0
author: rishi
tags: ["development", "flutter", "code"]
79 changes: 79 additions & 0 deletions packages/flutter-snippets/0.1.0/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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';"

0 comments on commit 639a7fc

Please sign in to comment.