Flutter Hands-on

Building the motion-logging app “Motion Note” with Riverpod, drift and BLE
日本語版はこちら

What you’ll build in this course

1

User management

Register names and show a list and details

2

Motion measurement

Receive data from two 6-axis sensors at 100Hz, display it and save it

3

Analysis & personal bests

Compute peak angular velocity and acceleration, and detect personal bests

4

BLE & localization

Connect to a real sensor and switch between Japanese and English

No hardware? You can complete the whole course with a fake sensor

Hardware used (optional)

DualGY521_M5Stamp

A home-made device with an M5Stamp Pico and two GY-521 (MPU6050) 6-axis sensors. Sends acceleration [g] and angular velocity [dps] over BLE at 100Hz

Source and spec

github.com/toshikinagahama/DualGY521_M5Stamp — see the README for commands and data format

  • Chapters 8 and 9 connect to this device. If you don’t have one, keep going with the fake sensor

App architecture

flowchart LR
  V["View<br/>screen"] --> VM["ViewModel<br/>screen state"]
  VM --> UC["UseCase<br/>business operation"]
  VM --> R["Repository<br/>data read/write"]
  UC --> R
  VM --> S["Service<br/>sensor (BLE/fake)"]
  R --> DB[("SQLite<br/>drift")]

  • Dependencies point only top → bottom. Lower layers don’t know about upper layers
  • Chapter by chapter, we build the boxes in this diagram one at a time

How to proceed

  1. At the start of each chapter, check the goals
  2. Read the explanation and write the code following the steps
  3. Go through the checkpoint items; once all are checked, move on to the next chapter

Code is shown as whole files

Copy it as-is and it runs. Highlighted lines were added or changed in that chapter (code boxes scroll)

Checks are saved

They are stored in your browser, so you can close it and resume later

Stuck? See the answer code

The finished version is in answer/

Chapters

Ch. Topic What you build
1 Project setup Packages, build.yaml
2 First screen View / ViewModel / freezed
3 Routing go_router
4 Database drift tables
5 Repository DB reads/writes
6 Device & subscriptions Fake sensor, StreamProvider
7 Domain layer Analysis rules and UseCase
8 BLE Connect to hardware with universal_ble
9 Auto-connect & connection state shared_preferences, app-wide state
10 Localization slang
11 Testing Repository / domain / packet data / ViewModel / connection

Prerequisites

  1. Install Flutter SDK 3.41 or later
  2. Install the Flutter extension in your editor (VS Code or Android Studio)
  3. Install Xcode to run on macOS, or Android Studio for Android
flutter --version
flutter doctor

Recommended target

We recommend starting with macOS (desktop). No emulator needed, and BLE works.

Checkpoint

CHECK 0 / 3