
In this section will complete a UI challenge and build a stopwatch application.
The two most important topics we will cover are tickers and matrix transforms.
- Tickers are at the foundation of the Flutter animation framework. By learning what they are and how to use them you'll get a much better understanding about how animations work under the hood.
- When you build custom UIs with animations, you'll often need to translate, rotate or scale widgets on screen. Matrix transforms are key in understanding how to do this.
We'll also get some practice working with widgets such as Stack, Align, Positioned, AspectRatio, LayoutBuilder, and cover a bit of state management.
Download the stopwatch_flutter.zip starter project, set up with Flutter and Dart SDK 2.12, and explore the custom stopwatch UI, animated elapsed time, and duration formatting.
Enable dark mode by applying ThemeData.dark to the MaterialApp and setting scaffoldBackgroundColor to Colors.black. Wrap the scaffold with AnnotatedRegion<SystemUiOverlayStyle> and apply SystemUiOverlayStyle.light to customize the status bar.
Set up a periodic timer to update the stopwatch by capturing the start time with DateTime.now and computing elapsed time, then render with a fixed-width ElapsedTimeText for readability.
Replace timer with a ticker that syncs to the screen, delivering 60 frames per second updates for a Flutter stopwatch and exposing elapsed time via callbacks.
Use matrix transforms to render the stopwatch UI with tick markers, five-second labels, and a clockwise clock hand, and move UI into a StopwatchRenderer widget that takes elapsed time.
Learn matrix transforms by using a stack to render ElapsedTimeText, wrap in an AspectRatio of 1.0, and add a padded container to create a centered square stopwatch UI.
Explore matrix transforms in Flutter by using the Transform widget and Matrix4 to translate, rotate, and scale widgets, control origin with alignment, and chain multiple transforms for 3D space effects.
Derive the circle radius from layout constraints with LayoutBuilder and pass it to StopwatchRenderer to render a responsive stopwatch circle, using a decorated container for visualization.
Design a reusable ClockHand widget that animates a clock hand clockwise using elapsed time and matrix transforms, then position and rotate it in a stack to complete a minute rotation.
Extend the stopwatch user interface by rendering 60 tick markers around a circle with a clockSecondsTickMarker widget, using matrix transforms, rotation, and color logic for multiples of five.
Complete the stopwatch user interface by adding five-second markers with a reusable ClockTextMarker widget, using matrix transforms, sized boxes, and a loop to position 60-second markings.
Add start, stop, and reset functionality to the stopwatch with custom buttons built from InkWell, Material, and clip oval. Use stack and align to position them and adjust aspect ratio.
Implement start, stop, and reset logic for a Flutter stopwatch by managing an is running flag, ticker control, and elapsed time with previously elapsed and currently elapsed getters.
Refactor the stopwatch UI to redraw only the parts that change at 60 fps. Implement a ticker UI widget and a global key to refresh only moving parts.
Explore further with a complete Flutter animations course, featuring seven hours of content to build a fully custom habit tracking app with advanced features and challenges.
Want to learn how to build completely custom and performant UIs in Flutter?
This practical course will teach you exactly that, by showing you how to create a clone of the iOS stopwatch app from scratch.
As part of this, you'll learn about the foundations of the Flutter animation framework and build a completely custom UI using:
Ticker and TickerProvider
Matrix Transforms
Stack, LayoutBuilder, AspectRatio, and other layout widgets
Would you like to:
build UIs that render every frame, in sync with the screen refresh rate, and without compromising performance?
rotate, scale, or translate widgets, and combine them all together to build custom UIs?
Then you've come to the right place.
This course is short and to the point. But it will give you valuable knowledge and a few tricks that will come handy in your future Flutter projects.
What does the completed project look like?
Go check the video preview for a complete overview of the project you'll build in this course.
Other things included in the course:
- How to switch betwen light and dark mode
- How to manage the stopwatch state and start, stop, and reset the timer
- How to optimize the application performance
- How to build modular code by creating small, reusable widgets
- A final challenge to test your knowledge
Frequently Asked Questions
Will we use Flutter 2?
Yes! The entire course uses Flutter 2 with Null Safety and I will keep it up to date.
What are the course prerequisites?
You should be already familiar with StatelessWidgets and StatefulWidgets, common layouts (Row, Column, Stack), and the foundations of state management in Flutter.