Blocks! Blocks! Blocks!
What are they? Why do I need to use Blocks? Can’t my app simply work after designing or adding the components or after adding the components?
Every non-programmer will come across these types of questions while starting to use App Inventor 2. In fact, I myself was confused about the blocks section at the beginning. So, let me help you to clear all those doubts.
How an app performs different operations?
When you use any app you are just seeing the things which are visible on the screen but, there is a lot of programming done in the beforehand by the developer which commands the app to work in that way.
For example, let us assume you have clicked a cart button or icon in an ecommerce app and the next thing which is visible on the screen of your phone are the list of items that you have added, their individual cost, Total cost, any tax and few other recommended products.
If you break down what the app is doing here then, you will realize that it is
- Collecting the info of the selected items or products
- Collecting the information about the quantity of each product
- Calculating the Total cost and also the taxes
- Refining the recommendations based on the products in your cart
- And much more
So, the cart page cannot show the information if all those operations have not been programmed by the app developer.
How do blocks make it easy to command the app?
Wait! You may be thinking App Inventor is a no code app development platform then, why should I need to programme the app. Yes! It’s true that you don’t need to programme but, as you are the mind behind it you should be able to command it to work in the way you want. And that is why App inventor has blocks.
Blocks are ready-made puzzle-like pieces that are very easy to understand and command the phone. The main application of blocks is that it eliminates typing of code and hence, errors due to mistakes in typing known as syntax errors are eliminated.
How to use the blocks?
Every operation in the app is dependent on the user’s intent. In fact, the opening of the app is also due to his/her intention of using it.
In App Inventor 2 we allow the user to interact with the help of User Interface components and drawing components. The interaction is then detected by event blocks like when|button1.clicked| do, when| Screen1|initialize| do….
After an interaction takes place we want the app to perform a specific operation connected to it. An operation is created using a combination of different blocks. And then, we connect it to an event block, so that it will run every time when a particular interaction has taken place between the user and the app.
Broadly, the type of blocks can be classified into two categories.
- Built-in blocks
- Component blocks
They are available to help us in various operations like comparing(logic), arranging (lists), adding (math) e.t.c
The blocks of different components are helpful in using their features. The component blocks can be further classified as event blocks, method blocks, and their properties blocks.
A combination of different blocks are used to create operations like calculating percentage; moving to a new screen, saving contacts, opening a webpage, playing a video, capturing an image and whatever you want the app to do.