Flutter CLI: 52 hidden samples

Nitish Kumar Singh
Flutter Community
Published in
4 min readAug 17, 2019

I am a big fan of CLI although in the video tutorial I avoid using it.

You might think why do I avoid it if I am a fan of CLI?
Just to feel Beginner comfortable, I use GUI as much as I can.

Beginner thinks that using Terminal/Command Prompt is like HackerMan.

https://media.giphy.com/media/iGpHt2H22k1orjgT9b/giphy.gif

This post is about CLI only and I’ll talk about one of the hidden features which are currently not available is GUI. So, GUI lover you can also read this.

CLI is not only HackerMan thing it’s used by normal programmer also. First time, I use the CLI at the age of 12.

Let’s come to the Flutter CLI.

Let’s talk what is actually hidden in Flutter CLI. So, In flutter CLI there is 52 different sample code/template of flutter app. Which teaches is how to use any particular widget.

  • Question: What do you get when you create a new flutter project?
  • Answer: A sample counter application which increases the number count on each Floating action button press.

The sample you get when you create a new flutter application is the default sample. You can get another sample app/sample example also.

These are the library and the corresponding number of examples.

  • Material: 32 examples
  • chip: 1 example
  • widget: 16 examples
  • services: 3 examples

How to use these samples?

This is the instruction for creating a flutter app from available sample examples.

flutter create  --sample=<id> <your_app_name>

I know you didn’t get this! What the heck is this id?

I will tell you that don’t worry. But promise me you will share this with your friends. As I told you there are 52 different sample examples so there must be some way yo identify the samples. So, id is the identifier for the sample examples. I am going to share the details of all available 52 examples in JSON format. So that you can easily read and understand it.

https://gist.github.com/nitishk72/aa5d31ddc9aabff94c3aae492ee947c0

If you want to create the first app then you need to write this command.

flutter create  --sample=material.FloatingActionButton.1 my_demo_app

This command will create a flutter application with the name my_demo_app and this time you are not going to get the default counter application.

You can find these kinds of command on flutter’s API/docs website.

https://api.flutter.dev/flutter/material/AppBar-class.html

In the above image, you can see that there are two tabs.

  • Sample
  • Sample in an App: Here you can find the fluter create command

There are 52 different examples means you will find these kinds of command on 52 different pages. API pages are more than 52 means all the pages don’t contain these kinds of command.

Here you can see there is a sample tab but there is no tab for sample in an App.

https://api.flutter.dev/flutter/material/TextField-class.html

This is the place, from where I started discovering the fluter create --sample command and came to all 52 available samples.

How I am soo confirm about 52 samples?

I am soo confirm because I got the JSON file from the flutter CLI tool. Yes, I got this from flutter CLI. I know some of you are interested in knowing that.

So to get this JSON file you need to use CLI tool again.

flutter create --list-samples=<path>
  • path: enter the path where you want to create the JSON file with the file name.

To get data of all available samples in the current working directory to write this command. This command will create a samples.json in the current working directory.

flutter create --list-samples=samples.json

If you like it and want to thank me then here you go

--

--

Nitish Kumar Singh
Flutter Community

Web🌐/ Mobile📱/ GraphQL / Cloud☁️ . Full-time programmer, part-time content creator, and Freelancer.