Git Product home page Git Product logo

awesome-flutter-snippets's Introduction

Awesome Flutter Snippets is a collection of commonly used Flutter classes and methods. It increases your speed of development by eliminating most of the boilerplate code associated with creating a widget. Widgets such as StreamBuilder and SingleChildScrollView can be created by typing the shortcut streamBldr and singleChildSV respectively.


Features

  • Speeds up development
  • Eliminates boilerplate
  • Supports complex widgets (Eg: Custom Clipper and Custom Paint)

 

Shortcut Expanded Description
statelessW Stateless Widget Creates a Stateless widget
statefulW Stateful Widget Creates a Stateful widget
build Build Method Describes the part of the user interface represented by the widget.
initS InitState Called when this object is inserted into the tree. The framework will call this method exactly once for each State object it creates.
dis Dispose Called when this object is removed from the tree permanently. The framework calls this method when this State object will never build again.
reassemble Reassemble Called whenever the application is reassembled during debugging, for example during hot reload.
didChangeD didChangeDependencies Called when a dependency of this State object changes
didUpdateW didUpdateWidget Called whenever the widget configuration changes.
customClipper Custom Clipper Used for creating custom shapes
customPainter Custom Painter Used for creating custom paint
listViewB ListView.Builder Creates a scrollable, linear array of widgets that are created on demand.Providing a non-null itemCount improves the ability of the ListView to estimate the maximum scroll extent.
listViewS ListView.Separated Creates a fixed-length scrollable linear array of list 'items' separated by list item 'separators'.
gridViewB GridView.Builder Creates a scrollable, 2D array of widgets that are created on demand. Providing a non-null itemCount improves the ability of the GridView to estimate the maximum scroll extent.
gridViewC GridView.Count Creates a scrollable, 2D array of widgets with a fixed number of tiles in the cross axis.
gridViewE GridView.Extent Creates a scrollable, 2D array of widgets with tiles that each have a maximum cross-axis extent.
customScrollV Custom ScrollView Creates a ScrollView that creates custom scroll effects using slivers. If the primary argument is true, the controller must be null.
streamBldr Stream Builder Creates a new StreamBuilder that builds itself based on the latest snapshot of interaction with the specified stream
animatedBldr Animated Builder Creates an Animated Builder. The widget specified to child is passed to the builder
statefulBldr Stateful Builder Creates a widget that both has state and delegates its build to a callback. Useful for rebuilding specific sections of the widget tree.
orientationBldr Orientation Builder Creates a builder which allows for the orientation of the device to be specified and referenced
layoutBldr Layout Builder Similar to the Builder widget except that the framework calls the builder function at layout time and provides the parent widget's constraints.
singleChildSV Single Child Scroll View Creates a scroll view with a single child
futureBldr Future Builder Creates a Future Builder. This builds itself based on the latest snapshot of interaction with a Future.
nosm No Such Method This method is invoked when a non-existent method or property is accessed.
inheritedW Inherited Widget Class used to propagate information down the widget tree.
mounted Mounted Whether this State object is currently in a tree.
snk Sink A Sink is the input of a stream.
strm Stream A source of asynchronous data events. A stream can be of any data type.
subj Subject A BehaviorSubject is also a broadcast StreamController which returns an Observable rather than a Stream.
toStr To String Returns a string representation of this object.
debugP Debug Print Prints a message to the console, which you can access using the flutter tool's logs command (flutter logs).
importM Material Package Import Material package.
importC Cupertino Package Import Cupertino package.
importFT flutter_test Package Import flutter_test package.
importAL App localisation Allows for the importation of app_localisation following generation.
mateapp Material App Create a new Material App.
cupeapp Cupertino Package Create a New Cupertino App.
tweenAnimationBuilder Tween Animation Builder Widget builder that animates a property of a Widget to a target value whenever the target value changes.
valueListenableBuilder Value Listenable Builder Given a ValueListenable and a builder which builds widgets from concrete values of T, this class will automatically register itself as a listener of the ValueListenable and call the builder with updated values when the value changes.
f-group Group Create a group test function.
f-test Test Create a test function.
f-testWidgets Test Widgets Create a testWidgets function.

Requirements

Vscode: 1.56.0

Known Issues

At this time, there are no known issues. If you discover a bug or would like to see a shortcut added, please create a pull request at our GitHub page.

Release Notes

4.0.0

  • Breaking: Change testWdigets to f-testWidgets to better align with function snippets
  • Support for group test function f-group
  • Support for app localisation import importAL
  • Support for Flutter 3
    • Migrate to super initialisers
    • Not on Flutter 3? The Flutter 2.xx branch is up to date and ready for you :)
  • Fixed Lint issue - Added const to applicable widgets

3.0.3

3.0.2

  • Removed trailing whitespaces (Thank you @leoshusar)
  • Make widgets default to Container only (Thank you @Ascenio)

3.0.1

  • Support for Listview.builder
  • Support for GridView.count
  • Support for GridView.extent

3.0.0

  • Update all widgets to null safety
  • Update engine to 1.56.0

2.0.4

  • Add Flutter test import (Thank you @arthurdenner #16)
  • Support for unit and widget test functions (Thank you @TNorbury #20)
  • Added support for Listview.Separated (Thank you @timilehinjegede #26)
  • Fixed inheritedW (Thank you @ianwith #22)

2.0.3

  • Support for BehaviorSubject (Thanks @sinadarvi #7)
  • Support for TweenAnimationBuilder
  • Support for ValueListenableBuilder
  • Fixed various bug fixes and typos

2.0.2

  • Resolved issue #6

2.0.1

  • Removed Stateful and Statless Widget since they are included with DartCode.
  • Added Material App.
  • Added Cupertino App.

2.0.0

  • Changed prefixes to use a keyword associated with the widget/function (in camel case)
  • Bug fixes

1.0.6

  • Added support for debug print
  • Added support for to string
  • Added support for importing Cupertino package
  • Added support for importing Material package (PR #2)
  • Added child logic to Stateless and Stateful widgets snippets (PR #3)

1.0.5

Critical bug fixes: - Adjusted tab stops to improve efficiency and workflow - Removed blank Containers from builders in favor of a tab stop with semi-colon - Added trailing comma at the end of child parameter

1.0.4

  • Fixed formatting
  • Removed unused tabs
  • Corrected spelling errors

1.0.3

Added support for: - Stream - Sink - Inherited Widget - Mounted - NoSuchMethod

1.0.2

Added support for: - Stateful Builder - Orientation Builder - Layout Builder - Single Child Scroll View - Future Builder

1.0.1

Added support for: - Stream Builder - Animated Builder - Custom Scroll View - Listview.Builder

1.0.0

Initial release of Awesome Flutter Snippets

awesome-flutter-snippets's People

Contributors

aaabramenko avatar arthurdenner avatar ascenio avatar biplab-dutta avatar brutalcoding avatar eligt avatar ianwith avatar javilledo avatar joaopedrocoelho avatar josealvaradoo avatar kabagouda avatar leonardorosaa avatar leoshusar avatar marcossevilla avatar nash0x7e2 avatar ninghao avatar rubensdemelo avatar runexes avatar sinadarvi avatar sultanic avatar tahatesser avatar taym95 avatar timilehinjegede avatar tnorbury avatar vinayakvivek avatar zfinix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

awesome-flutter-snippets's Issues

Compatible with VI Mode

I'm happy to use awesome-flutter-snippets. Thank you

Here is my problem.
1 Input "statefuW", then I got the snippets. That's awesome!
befor_delete
)

2 But after I tap "Delete" key, the snippets got wrong.
If I move cursor first,then press ”Delete“, this problem won't happen.
after_delete

3 My environment:

  • macOS Catalina
  • Visual Studio Code 1.44.2 , vim plugin version 1.13.1

I hope this problem to be fixed. Thanks a lot!

How do one use this extension?!

Hi,

The readme is missing one little and very important note, how to use this extension.
I've downloaded and installed it on my Visual Studio code, but I have not discovered the way to use it...

Thank you,
Yaniv

typo: oriantationBldr

One of the snippets is named "oriantationBldr". It should be "orientationBldr" (it creates an OrientationBuilder)

imports missing from statelessW

There is no import 'package:flutter/material.dart'; inside the snippet, leaving us to add missing import manually.

Added, Pull Request:
#60

(this is my first PR on GitHub, apologies for mistakes)

Add Null Safety support

Description

Hi, recently I've migrated to the latest version of Flutter which is currently 2.0.3.. which also supports Null Safety.
And few little issues I found while using this snippets (which are great btw), is that it doesn't support null safety features
for example if I use the snippet "statelessW" it will add the following

class WidgetTest extends StatelessWidget {
  const WidgetTest({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

but, since all Null Safety features are enabled, the Key property should be nullable (marked with '?').. like this

class WidgetTest extends StatelessWidget {
  const WidgetTest({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

I didn't tried all the snippets if they may have the same issue, but it would be awesome if you add this features to it.

Suggestions

  • you could add an option in the settings whether to enable null safe or not.
  • you could add 2 separate snippets one for null safe and one for non-null safe.
  • or something else

Config file

Maybe creating possible edits on snippets through the config file would be interesting.

Looking over #41 and my own experience using the use_super_parameters linter on my projects, for example, I would like to be able to use the statelessW and statefulW with the constructors starting with Name({super.key}).

Maybe adding the comma at the end by default on the constructors, making them const, removing BuildContext from the builder
at StatefulBuilder snippet (as suggested by avoid_types_on_closure_parameters linter), or any of these little changes.

And for the #41 maybe a property where you set whether this project uses null-safety or not.

Maybe even change the "always Container" rule for something like a const SizedBox.shrink() or something else chosen by the project owners.

[Feature Request] Auto Imports along with Snippets

First, thanks for creating these snippets. Being able to leverage modern conveniences like this makes using vim (neovim, in my case) extremely feasible, which is great because it's my favorite coding editor.

The context for this request is the following: When using coc.nvim, the standard completion suggestion for something like StatelessWidget includes the automatic import '...' line at the top of the file, if it doesn't exist. This is not only helpful so I don't have to remember where the import comes from and type it out myself, but it also prevents a lot of errors from appearing since the system won't be confused as to where from StatelessWidget comes.

When using awesome-flutter-snippets however, the automatic import is not done, which throws a lot of errors until I go add it in.

This is not a big deal, and I can imagine that it could be hard for a snippets engine to know if the import is already done or not, but I wanted to mention that it would be nice to have a single completion take care of the snippet as well as any necessary imports.

But I'm not sure where the functionality lies between coc.nvim and these snippets, so I don't know what the feasibility is of having something like this work.

Thanks for reading!

Bug : Exception in plugin Flutter Snippets 1.3.4

I'm getting a crash every time I start Android Studio

IDE version :

image

Plugin version

image

And I have flutter V3

Here's the log stack trace :

com.intellij.diagnostic.PluginException: Cannot create extension (class=FlutterContext) [Plugin: com.gionchat] at com.intellij.serviceContainer.ComponentManagerImpl.createError(ComponentManagerImpl.kt:932) at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.createInstance(XmlExtensionAdapter.java:88) at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapter(ExtensionPointImpl.java:486) at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapters(ExtensionPointImpl.java:434) at com.intellij.openapi.extensions.impl.ExtensionPointImpl.calcExtensionList(ExtensionPointImpl.java:241) at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensionList(ExtensionPointImpl.java:235) at com.intellij.codeInsight.template.impl.TemplateContextTypes.getAllContextTypes(TemplateContextTypes.java:20) at com.intellij.codeInsight.template.impl.TemplateContext$1.compute(TemplateContext.java:51) at com.intellij.codeInsight.template.impl.TemplateContext$1.compute(TemplateContext.java:31) at com.intellij.openapi.util.ClearableLazyValue.getValue(ClearableLazyValue.java:39) at com.intellij.codeInsight.template.impl.TemplateContext.readTemplateContext(TemplateContext.java:105) at com.intellij.codeInsight.template.impl.TemplateSettings.readTemplateFromElement(TemplateSettings.java:713) at com.intellij.codeInsight.template.impl.TemplateSettings.parseTemplateGroup(TemplateSettings.java:614) at com.intellij.codeInsight.template.impl.TemplateSettings$1.readScheme(TemplateSettings.java:199) at com.intellij.codeInsight.template.impl.TemplateSettings$1.readScheme(TemplateSettings.java:195) at com.intellij.configurationStore.schemeManager.SchemeLoader.loadScheme(schemeLoader.kt:187) at com.intellij.configurationStore.schemeManager.SchemeManagerImpl.loadSchemes(SchemeManagerImpl.kt:236) at com.intellij.codeInsight.template.impl.TemplateSettings.<init>(TemplateSettings.java:278) at com.intellij.codeInsight.template.impl.TemplateSettings.<init>(TemplateSettings.java:190) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at com.intellij.serviceContainer.ConstructorInjectionKt.instantiateUsingPicoContainer(constructorInjection.kt:47) at com.intellij.serviceContainer.ComponentManagerImpl.instantiateClassWithConstructorInjection(ComponentManagerImpl.kt:877) at com.intellij.serviceContainer.ServiceComponentAdapter.createAndInitialize(ServiceComponentAdapter.kt:48) at com.intellij.serviceContainer.ServiceComponentAdapter.access$createAndInitialize(ServiceComponentAdapter.kt:12) at com.intellij.serviceContainer.ServiceComponentAdapter$doCreateInstance$1.run(ServiceComponentAdapter.kt:42) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:705) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:647) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:63) at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:223) at com.intellij.serviceContainer.ServiceComponentAdapter.doCreateInstance(ServiceComponentAdapter.kt:41) at com.intellij.serviceContainer.BaseComponentAdapter.getInstanceUncached(BaseComponentAdapter.kt:113) at com.intellij.serviceContainer.BaseComponentAdapter.getInstance(BaseComponentAdapter.kt:67) at com.intellij.serviceContainer.BaseComponentAdapter.getInstance$default(BaseComponentAdapter.kt:60) at com.intellij.serviceContainer.ComponentManagerImpl.doGetService(ComponentManagerImpl.kt:590) at com.intellij.serviceContainer.ComponentManagerImpl.getService(ComponentManagerImpl.kt:573) at com.intellij.openapi.client.ClientAwareComponentManager.getFromSelfOrCurrentSession(ClientAwareComponentManager.kt:37) at com.intellij.openapi.client.ClientAwareComponentManager.getService(ClientAwareComponentManager.kt:22) at com.intellij.codeInsight.template.impl.TemplateSettings.getInstance(TemplateSettings.java:302) at com.intellij.codeInsight.template.impl.LiveTemplatesOptionsTopHitProvider.getOptions(LiveTemplatesOptionsTopHitProvider.java:24) at com.intellij.ide.ui.TopHitCache.lambda$getCachedOptions$0(TopHitCache.java:66) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705) at com.intellij.ide.ui.TopHitCache.getCachedOptions(TopHitCache.java:58) at com.intellij.ide.ui.OptionsTopHitProvider.getCachedOptions(OptionsTopHitProvider.java:53) at com.intellij.ide.ui.OptionsTopHitProvider$Activity.lambda$cacheAll$1(OptionsTopHitProvider.java:200) at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processWithPluginDescriptor(ExtensionPointImpl.java:293) at com.intellij.openapi.extensions.ExtensionPointName.processWithPluginDescriptor(ExtensionPointName.java:156) at com.intellij.ide.ui.OptionsTopHitProvider$Activity.cacheAll(OptionsTopHitProvider.java:196) at com.intellij.ide.ui.OptionsTopHitProvider$Activity.preload(OptionsTopHitProvider.java:177) at com.intellij.idea.ApplicationLoader$executePreloadActivity$1.run(ApplicationLoader.kt:412) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:705) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:647) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:63) at com.intellij.idea.ApplicationLoader.executePreloadActivity(ApplicationLoader.kt:402) at com.intellij.idea.ApplicationLoader.access$executePreloadActivity(ApplicationLoader.kt:1) at com.intellij.idea.ApplicationLoader$executePreloadActivities$2.run(ApplicationLoader.kt:467) at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183) Caused by: java.lang.ClassNotFoundException: FlutterContext PluginClassLoader(plugin=PluginDescriptor(name=Flutter Snippets, id=com.gionchat, descriptorPath=plugin.xml, path=~\AppData\Roaming\Google\AndroidStudio2021.2\plugins\FlutterSnippets.jar, version=1.3.4, package=null), packagePrefix=null, instanceId=48, state=active) at com.intellij.serviceContainer.ComponentManagerImplKt.doLoadClass(ComponentManagerImpl.kt:1489) at com.intellij.serviceContainer.ComponentManagerImplKt.access$doLoadClass(ComponentManagerImpl.kt:1) at com.intellij.serviceContainer.ComponentManagerImpl.loadClass(ComponentManagerImpl.kt:821) at com.intellij.openapi.extensions.impl.InterfaceExtensionImplementationClassResolver.resolveImplementationClass(InterfaceExtensionImplementationClassResolver.java:25) at com.intellij.openapi.extensions.impl.XmlExtensionAdapter.createInstance(XmlExtensionAdapter.java:65) ... 62 more

snippets code is not right

image

class name extends StatefulWidget {
  const name({Key? key}):super(key: key);

  @override
  State<name> createState() => _nameState();
}

class _nameState extends State<name> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Missing @override annotation in statefulW

When I convert a stateless widget to a stateful Widget, an @override annotation is added on createState:
image

image

But when creating a stateful Widget using the "statefulW" template no @override annotation is added on createState:
image

image

For consistency, the @OverRide annotation should also be added by the snippet since Dart Code adds it.

Support with old Flutter versions

I jump back and forth between new Flutter SDKs and projects with old SDKs regularly. Is it possible to add in a check for the Flutter SDK of the current project?

If project SDK > 2.0, use null safety json, otherwise use the old snippets.json

The fix for now is to go into the extension and manually switch the version back and forth, but it can be cumbersome if done regularly.

On initiating widgets

Can you change that when on initializing stateful or stateless widget, on widget container there is no "child" word? Every time i use this snippet it underscores red and it's so tilting to me. Maybe it's personal thing, but still - there is no reason for that " child" word to be there. And every time i see that underscoring i have to urge to immediately delete that line. Thanks.

Snippets missing from autocomplete

My flutter snippets have disappeared from the autocomplete pop-up. For example, if I create a new dart file, and want to import the material.dart package, I type 'import'. I used to then get an autocomplete with the 'importm' snippet being one of the options. Currently I only get the 'import' snippet:

image

However, when I hit Ctrl+Shft+P and select Insert Snippet, then 'importm' is one of the options:

image

I have tried uninstalling and reinstalling the Awesome Flutter Snippets extension.

This may be unrelated to this extension and purely be a VSCode issue, but I'm currently experiencing the issue with flutter snippets.

update snippets to flutter 3

currently the snippets don't seem to leverage flutter 3 features

e.g.:statelessW

  • expected result
class name extends StatelessWidget {
  const name({super.key});

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
  • actual result
class name extends StatelessWidget {
  const name({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Stateful and Statless Widget

Hi,

You removed Stateful and Statless Widget from this library because Dart Code has them. How to access them? I don't see anything similar in their documentation.

Thanks,
Adrian

Generate null-safe code

Currently snippets are generating legacy non null-safe code.

Expected behavior

Snippets are generating null-safe code.

404 Not Found

Hi, I tried to install this plugin but it is not showing up in the plugin store. In the marketplace section the 404 error is displayed. What's happening? Thanks for sharing knowledge.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.