Flutter Zero to One #1

Welcome to part one of my free Flutter course called “Flutter Zero to One”. The goal of this course is to take you from zero knowledge to being able to make the apps you want using Flutter. If you consider the old expression “Give a person a fish, and you feed them for a day. Teach a person to fish and you feed them for a lifetime.” My aim is to not just give you a fish but to teach you how to fish yourself. Fishing in this case means making apps.

A lot of tutorials help you create an app, but in a way that is like just giving you an app. A lot of important steps are skipped. I want to teach you to become an independent developer. I want to give you the knowledge that I use to be able to make my apps.

What we will cover in this course

Today:
What are variables in programming?

Lesson 2:
What are methods in programming? How do I use them? Why should I care?

Lesson 3:
What are if else statements in programming? How do I use them? Why should I care?

Lesson 4:
What are data structures in programming? How do I use them? Why should I care?

Lesson 5:
What are classes in programming? How do I use them? Why should I care?

Lesson 6:
How to build an app in Flutter. Building your first app (Note app #1)

Lesson 7:
How to build an app in Flutter. Building your first app (Note app #2)

I might add more lessons if these first seven get a good response and I have good ideas for more lessons. There are lots of more topics to cover. However, I do believe that after following these seven lessons you will be capable of building apps. You will also have a basis of programming knowledge that will help you explore new topics and learn on your own. So this is my attempt at making my own Udemy course but short, sweet and free. So I hope you enjoy it and now lets get started!

Variables. What are they, how do we use them and why should you care?

Programming and math is very related and so a variable in programming is similar to a variable in maths. Also if you belong the the group of people who start cold sweating as soon as maths are mentioned, then relax, there’s virtually no maths involved when making an app. You will be able to understand what I’m about to explain. And what I’m about to explain is as difficult as the maths is going to get for us in this course.

I want to be thorough when explaining things so that I avoid assuming too much prior knowledge. If you already understand a concept that I am explaining I encourage you to just skip ahead.


Whenever I say “a variable” I am referring to something that has a value that can be changed. The opposite would be a constant, something that has a value that cannot be changed. An example of a variable could be X, Y, Z or myVariableName. You can name your variable anything you want, a letter, word, phrase or anything else you might come up with. Once we have decided on a variable name that we like, we can then assign this variable some value:

x = 10 

Now, whenever we see ‘x’ we know that this stands for 10.  Therefore x * 2 is equal to 20.  To make it even clearer we could change our variable name to ’TEN’. So instead of x = 10 we now have TEN = 10 .  So now it might make more sense that TEN * 2 is equal to 20.

TEN = 10
TEN * 2 = 20

This is exactly how variables work in programming. We can name a variable whatever we want and then we can assign it to some value. From that point forward when we use our variable name it will represent the value we chose for it. So if we say that my age = 25 then if we ever refer to the variable age we know that this represents 25.

How do we use variables?

There are a few different types of variables that we can use depending on the value we want to assign it.  There are a few different types of values, the most common ones are: ‘String’, ‘Integer’, ‘double’, ‘Boolean’, ‘var’. Stop! if you were just trying to memorise them just stop. Don’t worry you will learn them automatically. 

How do we know when to use which value?
Lets try a few things. Lets say that we want to create all of our family members in code. okay so what are our family members? We will go with mother, father, sister and me. These will be our variable names:

mother =
father =
sister =
me =

And best practice is to make your variable names as descriptive as possible. Within reason of course. I want these variable names to represent each persons name. I could make it more descriptive by ending each variable name with ‘Name’.

motherName =
fatherName =
sisterName =
meName =

Convention is to make each new word in a variable name have a capital letter, to make it easier to read. This convention changes depending on the language. In Python for instance we use underscore. So the variable name would then look like this: mother_name

Alright so now we have our variable names lets give them some values:

motherName = "Khaleesi" 
fatherName = "Jon" 
sisterName = "Arya" 
meName = "Kalle" 

As you can see I have put all the names in quotation marks. If your value is text then it needs to be in quotation marks. But if it is a number then it doesn’t. Names are clearly going to be text, what variable type should we use for this? We can consider text as a string of characters. So the variable type for text is going to be String. Our variables will now look like this:

String motherName = "Khaleesi"
String fatherName = "Jon"
String sisterName = "Arya"
String meName = "Kalle"

The first thing we do is give our variable a type. What type it should be depends on what value we want to give it. After deciding the type we can come up with our variable name which can be whatever you want. Whatever your heart desires. Then we assign our variable a value. The value needs to be of the same value type that we set for our variable.

The value types

Numbers
Int stands for integer which is a whole number. Integers are 1, 2,3 4 5 6 7 8 etc all the way up as far as you can count, almost. You cannot assign an integer a value of 1.5. That will not work. How do you use numbers like that, that have a number on both sides of the comma? In a sense they have two numbers, on on each side. Thats double the trouble isn’t it? Yes you got it for numbers where you need a comma you use the type Double.
Use integer when you are unlikely to ever care about the number behind the comma. Like age, number of fingers, number of children etc. Use double when you might care about more precise info like with price, height, weight, amount left of inheritance if my parents were to suddenly disappear..

Boolean & var
The last two “boolean” and “var”. What could they be?
Well boolean can be either true or false. It can only be true or false nothing else can be assigned to a boolean. When I first learned to code I didn’t see the need for this so I just didn’t use it. But this is a very useful variable type in certain cases. For instance if you have a on and off switch then you could consider off as false and on as true. So if we imagine this on-off switch being connected to a light. Then we want to check, “Are the lights still on at home?”. We take a look at our boolean to see: 

bool lightsOn = true 

As we can see it is true that the lights are on. And when someone flicks the switch to off we can turn our variable to false.

bool lightsOn = false 

Our program now knows to turn the lights off.

Lastly we have our trusty friend “var” this is like a safety type in essence and this can be any type. So if you are unsure of what a value is going to be then var can kind of save you. However, use this sparingly. Mostly the use case for this is when you are receiving data from an external source and you might not know what type of stuff you will get.

Conclusion

Alright, that is the end of lesson one in this free Flutter course. I hope I was able to explain it in a way that you were able to understand. And I also hope that you will stick with me throughout this course. I will put in my best effort to create something that will teach you everything you need to know to become a great Flutter developer!

Check out lesson #2 – Flutter Zero to One lesson #2 – What are methods in programming?

Clean Code Friday

A short email from me every Friday with a few of the most interesting things I have explored and discovered in the past week. The content is exclusive to the email and does not get posted anywhere else.

    Powered By Kalle Hallden

    13 Comments

    1. Avatar
      Vanice Leung
      September 28, 2019

      This website is so nice and finally there is a coding tutorial from Kalle. 🎉🎉

      Reply
      1. Avatar
        caleb
        October 2, 2019

        Thanks so Much From Kenya.. AND
        Looking foward to Learn Flutter

        Reply
        1. Avatar
          mikaelson
          October 7, 2019

          Uganda is also learning..
          Thanks man for the intiative

          Reply
    2. Avatar
      Jude Oyovbaire
      October 1, 2019

      Basics clearly explained… Thank you.

      Reply
    3. Avatar
      Sanchit Pillai
      October 4, 2019

      WoW! This course is very precise and to the point Kalle. Its almost like a friend teaching me the concepts of programming. Pretty excited to learn through this.

      Reply
    4. Avatar
      Denny Raymond
      October 5, 2019

      Love this section

      Reply
    5. Avatar
      Rizal Abul Fata
      October 6, 2019

      Thanks kalle, I always waiting from you.
      Your ideas, and innovation.
      And then this tutorial is perfect

      Terima kasih

      Reply
    6. Avatar
      Nuaiman Ashiq
      October 7, 2019

      Thanks Kalle
      typical of you coming up with amazing contents. Keep up the good work man <3

      Reply
    7. Avatar
      Matěj Novotný
      October 7, 2019

      I recently build my first app and it is super awesome. I am looking forward to next “chapter” i like yout way of coding.

      Reply
    8. Avatar
      Sudi Dav
      October 9, 2019

      Thanks man! and keep it up!! from Africa!!lol

      Reply
    9. Avatar
      Kang Gunawan
      October 16, 2019

      I will like this and this is my chance to learn. thanks.

      Reply
    10. Avatar
      Karwan
      November 6, 2019

      Thank you for your free teaching

      Reply
    11. Avatar
      OhenebaAduhene
      November 7, 2019

      Thank you so much, finally you helped me broaden my understanding about variables and how they work. Looking forward to you to explore and learn more 👨‍💻👨‍💻👨‍💻

      Reply

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Join Clean Code Friday