Building a Calculator Layout using Dart's Flutter Framework

What Will I Learn?

  • You will learn how to use flutter expanded widgets to fill out areas
  • You will learn how to make use of axis alignment in flutter
  • You will learn how to use text styling to manipulate the font properties of text widgets
  • You will learn how to make classes that generate widgets to save code

Requirements

Difficulty

  • Intermediate

Description

In this video tutorial, we build out a simple calculator layout using the flutter framework. The purpose of this exercise is to showcase the some of the layout properties in the flutter framework such as the expanded widget, the flex property, cross and main axis alignment and text styling. A calculator is a perfect choice for looking at these types of widgets because it requires the use of multiple rows of buttons and a display. Rather then using a simple grid view widget, we can easily manipulate the spacial relationship of our buttons and display by using a combination of these various different widgets.

The expanded widget is a widget that allows us to directly effect how elements fill the space of a larger widget. We can achieve this by setting up the flex of each of the expanded widgets inside of the parent container. The flex directly allows us to change how much room a child widget will take up inside of that parent widget. We can then fine tune the spacial relationships of these items using the cross and main axis alignment properties. The cross axis is the column reverse axis which runs horizontal to the main axis which is the vertical axis. Flutter's text styling allows us to change the font size, font weight, font color, and a few other properties. We can also add a third party font to the project to further customize our fonts.

We also make use of a class that can help us generate a list of widgets to fit inside of a column. In this way we can programmatically generate the buttons of the calculator by just putting in a character representation for the button. For buttons that use more then one character, we can use a ternary operator to replace the original one character representation for user clarity.

The source code for this project can be found here

Video Tutorial

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
5 Comments