Last couple of days, I am following the lesson to create an mobile apps that will allow 2 players to roll a virtual dice on the mobile phone to see who has the highest point.
To roll the dice, the player just need to tap on the dice. The app will detect a press event and do that action.

New widget or class that I learned were Expanded, TextButton, OnPressed, setState, Stateless and Stateful.
For this application, I will be using stateful widget because I will need to keep track of left and right dice value and display the images based on the value. Those information are kept in the state. Hence stateful.

Similar to the previous application, started off with Material3 for the framework. Nothing special here.

One cool thing about Android Studio is that there is a shortcut key that will insert a StatefulWidget code for the developer to put in their own flow, instead of writing all these from scratch. Very cool.

One variation was to roll both dices when pressed. Since the code is the same, created a function “throwDice” that will set the dice number. Using Dart.math library Random function to perform the task, for both dice.

build widget is pretty cool. It will build the entire UI when required. In this apps, started with Row of two children, each is for one dice, using Expanded widget to fill the space, and using TextButton to detect for any event on and calling throwDice if there is one.

That’s it. Simple apps. But fun. Learning new widget and seeing how it behave on the phone.
Onward, 1% better everyday.
