Create a Stopwatch App with Flutter

Create a Stopwatch App with Flutter

Learn how to create a Stopwatch App with Flutter. Flutter provided a Stopwatch class. It can be started or stopped, and the elapsed time can be read from the elapsedMilliseconds property. So technically we can set up a page with a Stopwatch instance, then simply display the stopwatch.elapsedMilliseconds.

I’ve been learning Flutter and Dart language recently and they really impressed me. Flutter is greatly inspired by React and many concepts are already familiar: stateful/stateless, render function, component hierarchy, etc. As for Dart language which backs Flutter, it inherits numerous of the best features from other languages while keeping off from the bad things, so if you already know python, JavaScript, C++, you can pick up Dart very quickly.

Okay, let’s go back to the main topic of this article: creating a stopwatch app. There are some posts about how to build a stopwatch (like this), but I would like to share an alternative approach.

The example in this post used Android Studio. If you haven’t done so, please follow the “Get started” part in the Flutter docs to setup Flutter and Android Studio.

The Idea

Flutter provided a Stopwatch class. It can be started or stopped, and the elapsed time can be read from the elapsedMilliseconds property. So technically we can set up a page with a Stopwatch instance, then simply display the stopwatch.elapsedMilliseconds.

However, there is one problem: Stopwatch does not provide any callbacks, so we have no idea when to perform a re-render. Here the Timer class comes to the rescue. It triggers a callback with a given interval. Therefore, we can use a Timer to trigger the re-render, read stopwatch.elapsedMilliseconds and rebuild the page.

flutter programming dart

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Google's Flutter 1.20 stable announced with new features - Navoki

Google has announced new flutter 1.20 stable with many improvements, and features, enabling flutter for Desktop and Web

What is Flutter and why you should learn it?

Flutter is an open-source UI toolkit for mobile developers, so they can use it to build native-looking Android and iOS applications from the same code base for both platforms. Flutter is also working to make Flutter apps for Web, PWA (progressive Web-App) and Desktop platform (Windows,macOS,Linux).

Flutter - Complex JSON Serialization in Dart | 3 Methods | JSON to Dart/Flutter

Learn to convert any complex JSON data structures into Dart data classes in Flutter using these 3 methods.Web 1 : https://javiercbk.github.io/json_to_dart/We...

Dart Programming Tutorial | Learn the Dart for Flutter

Learn Dart Programming for Flutter- Beginners Tutorial - Udemy Free Course

6 Things About HTTP Request in Dart For Beginners

Here is an http request to get a user's data using GET request, First, we have to make an async function that returns a type. If you are here and a beginner, that means you want to learn everything about making an API request using Dart in Flutter, then you are in the right place for the HTTP tutorial.