Building a Countdown Timer with a Custom Painter and Animations in Dart's Flutter Framework

What Will I Learn?

  • You will learn how to build a custom painter and canvas to build out shapes and animations
  • You will learn how to use aligns, aspect ratios and position fill widgets
  • You will learn how to use complex custom theme data sets

Requirements

Difficulty

  • Intermediate

Description

In this Flutter video tutorial, we build out a countdown timer application. This application makes use of a custom painter and canvas to generate two circle shapes. The first circle shape acts as a background circle and the second one slowly fills out the background circle giving the user some idea of how much time has passed.

We are able to style the application by using a theme widget inside of the main root widget. This theme data widget lets us setup the canvas color, icon theme, accent color and the brightness of the colors. We are then able to access these values through the build context in any of our widgets. We also are able to access some of the default values that come in the basic flutter theme; including the subhead and display4 text sizes.

Inside of the circles in our animation, we place three zeroes, one for the minutes and two for the passing seconds. These numbers change in real-time based on the amount of time that is set for the duration of our animation. This means that if the animation runs for 240 seconds, then the countdown will count from 4 minutes to 0 seconds.

Our layout makes use of some new widgets; the positioned fill widget, the align widget, and the aspect ratio widget. Each of these widgets focus on one specific property. The position fill widget lets us will up a stack by default by setting the position properties to 0.0 by default. The align widget is a container with a focus on the alignment property and the aspect ratio widget is a container with a focus on the aspect ratio property.

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
4 Comments