Skip to content

Commit 4137d51

Browse files
committed
Initial commit
0 parents  commit 4137d51

File tree

7 files changed

+112
-0
lines changed

7 files changed

+112
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
/flutter-snippets.zip
3+
/.idea/
4+
/out/

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| Shortcut| Flutter Docs| Description|
2+
| ---------- | ------------------------ | -------------- |
3+
|`alertDialog`|[View Docs](https://docs.flutter.io/flutter/widgets/AlertDialog-class.html)|Creates a showDialog that returns with AlertDialog|
4+
|`futureBldr`|[View Docs](https://docs.flutter.io/flutter/widgets/FutureBuilder-class.html)|Creates a FutureBuilder|
5+
|`listViewBldr`|[View Docs](https://docs.flutter.io/flutter/widgets/ListView.builder.html)|Creates a ListView.builder()|
6+
|`streamBldr`|[View Docs](https://docs.flutter.io/flutter/widgets/StreamBuilder-class.html)|Creates a StreamBuilder|
7+

flutter-snippets.iml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="PLUGIN_MODULE" version="4">
3+
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
4+
<component name="NewModuleRootManager" inherit-compiler-output="true">
5+
<exclude-output />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
9+
</content>
10+
<orderEntry type="inheritedJdk" />
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
<orderEntry type="library" name="Dart SDK" level="project" />
13+
</component>
14+
</module>

resources/META-INF/plugin.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<idea-plugin>
2+
<id>com.herbert.george.flutter-snippets</id>
3+
<name>Flutter Snippets</name>
4+
<version>0.1</version>
5+
<vendor>George Herbert</vendor>
6+
<description>Provides live templates for Flutter to save time writing boiler plate</description>
7+
<idea-version since-build="141.0"/>
8+
<extensions defaultExtensionNs="com.intellij">
9+
<defaultLiveTemplatesProvider implementation="FlutterTemplateProvider"/>
10+
<liveTemplateContext implementation="FlutterContext"/>
11+
</extensions>
12+
</idea-plugin>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templateSet group="Flutter">
3+
<template name="futureBldr"
4+
value="FutureBuilder(&#10;future: $FUTURE$,initialData: $INITIAL$,builder: (BuildContext context, AsyncSnapshot snapshot) {if (snapshot.hasData) {if (snapshot.data!=null) {return $WIDGET$;} else {return CircularProgressIndicator();}}),"
5+
description="Create FutureBuilder" toReformat="true" toShortenFQNames="true">
6+
<variable name="FUTURE" expression="&quot;future&quot;" defaultValue="" alwaysStopAt="true"/>
7+
<variable name="INITIAL" expression="&quot;initialValue&quot;" defaultValue="" alwaysStopAt="true"/>
8+
<variable name="WIDGET" expression="&quot;widget&quot;" defaultValue="" alwaysStopAt="true"/>
9+
<context>
10+
<option name="DART_STATEMENT" value="true"/>
11+
</context>
12+
</template>
13+
<template name="streamBldr"
14+
value="StreamBuilder(stream: $STREAM$, builder: (BuildContext context, AsyncSnapshot snapshot) {if(snapshot.hasError) return $ERRORWIDGET$; switch (snapshot.connectionState) {case ConnectionState.none: return $DEFAULTWIDGET$;case ConnectionState.waiting: return $LOADINGWIDGET$;case ConnectionState.active: return $ACTIVEWIDGET$; case ConnectionState.done: return $FINISHEDWIDGET$;}return null; // unreachable}, ),"
15+
description="Create StreamBuilder" toReformat="true" toShortenFQNames="true">
16+
<variable name="STREAM" expression="&quot;stream&quot;" defaultValue="" alwaysStopAt="true"/>
17+
<variable name="DEFAULTWIDGET" expression="&quot;ConnectionNone&quot;" defaultValue="" alwaysStopAt="true"/>
18+
<variable name="LOADINGWIDGET" expression="&quot;ConnectionWaiting&quot;" defaultValue="" alwaysStopAt="true"/>
19+
<variable name="ACTIVEWIDGET" expression="&quot;ConnectionActive&quot;" defaultValue="" alwaysStopAt="true"/>
20+
<variable name="FINISHEDWIDGET" expression="&quot;ConnectionDone&quot;" defaultValue="" alwaysStopAt="true"/>
21+
<context>
22+
<option name="DART_STATEMENT" value="true"/>
23+
</context>
24+
</template>
25+
<template name="listviewBldr"
26+
value="ListView.builder(itemCount: $COUNT$,itemBuilder: (BuildContext context, int index) {return $WIDGET$;}, ),"
27+
description="Create ListView.builder" toReformat="true" toShortenFQNames="true">
28+
<variable name="COUNT" expression="&quot;future&quot;" defaultValue="" alwaysStopAt="true"/>
29+
<variable name="WIDGET" expression="&quot;widget&quot;" defaultValue="" alwaysStopAt="true"/>
30+
<context>
31+
<option name="DART_STATEMENT" value="true"/>
32+
</context>
33+
</template>
34+
<template name="showDialog"
35+
value="showDialog&lt;void&gt;(&#10;context: $context$,&#10;barrierDismissible: $dismiss$, // false = user must tap button, true = tap outside dialog&#10;builder: (BuildContext dialogContext){&#10;return AlertDialog(&#10;title: Text('$title$'),&#10;content: Text('$content$'),&#10;actions: &lt;Widget&gt;[&#10;FlatButton(&#10;child: Text('$buttonText$'),&#10;onPressed: () {&#10;Navigator.of(dialogContext).pop(); // Dismiss alert dialog&#10;},&#10;),&#10;],&#10;);&#10;},&#10;);"
36+
description="New AlertDialog" toReformat="false" toShortenFQNames="true">
37+
<variable name="context" expression="&quot;context&quot;" defaultValue="" alwaysStopAt="true"/>
38+
<variable name="dismiss" expression="&quot;barrierDismissible&quot;" defaultValue="" alwaysStopAt="true"/>
39+
<variable name="title" expression="&quot;title&quot;" defaultValue="" alwaysStopAt="true"/>
40+
<variable name="content" expression="&quot;dialogBody&quot;" defaultValue="" alwaysStopAt="true"/>
41+
<variable name="buttonText" expression="&quot;buttonText&quot;" defaultValue="" alwaysStopAt="true"/>
42+
<context>
43+
<option name="DART_STATEMENT" value="true"/>
44+
</context>
45+
</template>
46+
</templateSet>

src/FlutterContext.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import com.intellij.codeInsight.template.TemplateContextType;
2+
import com.intellij.psi.PsiFile;
3+
import org.jetbrains.annotations.NotNull;
4+
5+
public class FlutterContext extends TemplateContextType {
6+
protected FlutterContext() {
7+
super("FLUTTER", "Flutter");
8+
}
9+
10+
@Override
11+
public boolean isInContext(@NotNull PsiFile file, int offset) {
12+
return file.getName().endsWith(".dart");
13+
}
14+
}

src/FlutterTemplateProvider.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import com.intellij.codeInsight.template.impl.DefaultLiveTemplatesProvider;
2+
import org.jetbrains.annotations.Nullable;
3+
4+
public class FlutterTemplateProvider implements DefaultLiveTemplatesProvider {
5+
@Override
6+
public String[] getDefaultLiveTemplateFiles() {
7+
return new String[]{"liveTemplates/Flutter"};
8+
}
9+
10+
@Nullable
11+
@Override
12+
public String[] getHiddenLiveTemplateFiles() {
13+
return new String[0];
14+
}
15+
}

0 commit comments

Comments
 (0)