Finishing our Calculator Application with Dart's Flutter Framework

in #utopian-io6 years ago (edited)

What Will I Learn?

  • You will learn how to pass callback functions as state through widgets
  • You will learn how to make use of cases and switch statements in the Dart and Flutter
  • You will learn how to refactor a flutter application to separate the state and the layout
  • You will learn how to decouple the state of a flutter app from its layout

Requirements

Difficulty

  • Intermediate

Description

In the last Flutter video tutorial, we built out a calculator layout using the expanded and the flex concepts among other ideas. In this tutorial, we finish this application by implementing most of the features and logic of the calculator. This is achieved by way of an inherited widget which passes around a callback function which is used to update the state of our stateful widget. We refactor the layout of our calculator so that it is in a stateless widget and then add an inherited widget to our widget tree below our calculator state widget. This allows us to simplify the logic of our application and make it so that we do not have to create multiple callback functions for every single one of our buttons. The use of the inherited widget also decouples the main state of the application from the layout in a way that makes it easy for the renderer tree to just re-render the components in use.

We also make use of the Dart switch keyword to let us filter through the various key presses that a user can preform in our calculator. This lets us apply behavior to our application based on the actions of the user. We save the values put into the calculator by the user through variables which are maintained by our inherited widget and then we also save the operator so that we know which operator the user wants to apply to these values. We also add functionality to allow the user to clear the display and all of the state from the application as well as functionality to allow the user to keep chaining multiple operations together.

The source code for this project can be found here

Video Tutorial

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @creon, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Thank you for moderating my content.

Hey @tensor I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.033
BTC 63968.82
ETH 3136.80
USDT 1.00
SBD 4.28