DEV Community

Cover image for Build a Guided Meditation App in Flutter
Muhammad Uzair
Muhammad Uzair

Posted on Originally published at uzairxdev.online

Build a Guided Meditation App in Flutter

Meditation apps look simple from the outside: a timer, a calm voice, a breathing circle that grows and shrinks. Underneath that calm surface is a real engineering problem. The app has to keep audio playing while the screen is off, animate a breathing pacer smoothly without dropping frames, remember streaks and progress across days, and do all of it inside an interface that never shouts for attention.

This guide builds a guided meditation app in Flutter from the ground up, following the same shape as Inhalo, a breathing and meditation app built in Flutter with guided sessions, audio playback, and progress tracking. You will model meditation sessions in Dart, build a breathing pacer with AnimationController, play guided audio with just_audio, track streaks with on-device storage, and design a calm interface that helps people actually return the next day.

What does a guided meditation app need?

A guided meditation app needs four pieces that work together: a library of sessions, a breathing pacer, an audio player that keeps playing in the background, and progress tracking that rewards coming back. Everything else, such as themes, sounds, and reminders, is decoration around those four pieces.

The session library is the content: short guided meditations grouped by goal, such as stress relief, better sleep, or focus before work. Each session needs a title, a duration, a category, and an audio file. The breathing pacer is the visual anchor: a circle that grows while the user breathes in and shrinks while they breathe out, giving the eyes something slow to follow. The audio player is the core of the experience, because a meditation app that stops playing when the screen locks is useless. Progress tracking is what turns one session into a habit: minutes meditated, total sessions, and a streak that counts consecutive days.

Inhalo, the app this guide is modeled on, combines exactly these pieces: guided breathing exercises and meditation routines, personalized sessions for stress, anxiety relief and sleep, audio playback for guided tracks and ambient sounds, and progress tracking, all inside a serene, distraction-free interface. Get the four pieces right and the app works; polish them and people come back.

How do you model a meditation session in Dart?

A meditation session in Dart is a plain data class with the fields the library screen and the player screen both need. Keep the model small and explicit: an id, a title, a category, a duration in minutes, an audio asset path, and a short description. The category drives the library grouping, the duration drives the timer and the progress math, and the audio asset path is what the player loads.

Here is a session model that covers a real library without overengineering:

\`dart
class MeditationSession {
const MeditationSession({
required this.id,
required this.title,
required this.category,
required this.durationMinutes,
required this.audioAsset,
required this.description,
});

final String id;
final String title;
final String category;
final int durationMinutes;
final String audioAsset;
final String description;
}

const sessions = [
MeditationSession(
id: 'morning-calm',
title: 'Morning Calm',
category: 'Stress Relief',
durationMinutes: 5,
audioAsset: 'assets/audio/morning-calm.mp3',
description: 'A gentle five-minute session to start the day settled.',
),
MeditationSession(
id: 'deep-sleep',
title: 'Deep Sleep',
category: 'Sleep',
durationMinutes: 10,
audioAsset: 'assets/audio/deep-sleep.mp3',
description: 'Slow breathing and a body scan to drift off.',
),
];
`\

Two details matter here. First, keep the audio files bundled as assets for the first version, so sessions play without a network connection and without a backend to maintain. Second, keep the first sessions short: five minutes is long enough to feel real and short enough that a new user finishes it. A finished session is the whole retention strategy, and short sessions finish.

How do you build a breathing pacer animation?

A breathing pacer in Flutter is an AnimationController driving a scale Tween, with the phase label switching on the controller status listener. The circle grows during the inhale and shrinks during the exhale, and the text tells the user which phase they are in. A four-second duration with an ease-in-out curve reads as natural, because the motion starts slow, speeds up, and slows down again, matching how a real breath feels.

Here is a complete pacer widget. The controller runs forward for the inhale and reverses for the exhale, flipping the label each time it reaches an end:

\`dart
class BreathingPacer extends StatefulWidget {
const BreathingPacer({super.key});

@override
State createState() => _BreathingPacerState();
}

class _BreathingPacerState extends State
with SingleTickerProviderStateMixin {
late final AnimationController _controller;
late final Animation _scale;
String _phase = 'Breathe in';

@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 4),
)..addStatusListener((status) {
if (status == AnimationStatus.completed) {
setState(() => _phase = 'Breathe out');
_controller.reverse();
} else if (status == AnimationStatus.dismissed) {
setState(() => _phase = 'Breathe in');
_controller.forward();
}
});
_scale = Tween(begin: 0.7, end: 1.0).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
);
_controller.forward();
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
AnimatedBuilder(
animation: _scale,
builder: (context, child) {
return Transform.scale(
scale: _scale.value,
child: Container(
width: 200,
height: 200,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Color(0xFF7FA8A0),
),
),
);
},
),
const SizedBox(height: 24),
Text(_phase, style: const TextStyle(fontSize: 20)),
],
);
}
}
`\

Three rules keep this smooth. First, always dispose the controller, or it keeps ticking after the screen is gone. Second, animate with AnimatedBuilder or a scale transform rather than rebuilding the whole screen on every frame, so the pacer never causes jank elsewhere. Third, respect users who prefer reduced motion: check MediaQuery.of(context).disableAnimations and show a static circle with the phase text instead of the animation. For a deeper look at this pattern, see Build a Breathing Pacer Animation in Flutter.

How do you play guided audio and ambient sounds?

Guided audio in Flutter is best handled with the just_audio package, which plays a voice track and an ambient loop at the same time and keeps playing when the app goes to the background. Add just_audio and audio_session to pubspec.yaml, then configure an AudioSession for playback so the operating system treats the app as a media player: the audio continues with the screen off and controls appear on the lock screen.

The basic player setup is only a few lines. Load the session audio asset, press play, and the voice track starts:

\`dart
final player = AudioPlayer();

Future playSession(MeditationSession session) async {
await player.setAsset(session.audioAsset);
await player.play();
}
`\

Ambient sound needs a second player running underneath the voice. Create another AudioPlayer, load a rain or brown noise loop, set its loop mode to LoopMode.one so it repeats forever, lower its volume so it sits behind the voice, and play it alongside the first player:

\`dart
final ambientPlayer = AudioPlayer();

Future startAmbientSound() async {
await ambientPlayer.setAsset('assets/audio/rain-loop.mp3');
await ambientPlayer.setLoopMode(LoopMode.one);
await ambientPlayer.setVolume(0.3);
await ambientPlayer.play();
}
`\

Pause both players together when the session ends or the user taps pause, and dispose both when the player screen is removed. One practical warning: test background playback on a real device, not only the emulator, because audio session behavior differs between the two. For the full background audio setup, see Build a Sleep Sounds App in Flutter.

How do you track progress and streaks?

Progress tracking in a meditation app is three numbers: total minutes, total sessions, and the current streak of consecutive days. Streaks are the strongest retention mechanic in this kind of app, because losing a streak costs the user something and keeping it costs them five minutes. Store all three numbers on-device with shared_preferences, so progress survives app restarts without an account or a backend.

The streak rule is simple once it is written down: when a session finishes, increment the streak if the last session was yesterday, keep it unchanged if the last session was today, and reset it to one if the gap is longer. Here is that logic with the date helpers:

\`dart
bool _isSameDay(DateTime a, DateTime b) =>
a.year == b.year && a.month == b.month && a.day == b.day;

bool _isYesterday(DateTime date, DateTime today) {
final yesterday = today.subtract(const Duration(days: 1));
return _isSameDay(date, yesterday);
}

Future recordCompletedSession(int minutes) async {
final prefs = await SharedPreferences.getInstance();
final today = DateTime.now();
final lastRaw = prefs.getString('lastSessionDate');
final lastDate = lastRaw == null ? null : DateTime.parse(lastRaw);

var streak = prefs.getInt('streak') ?? 0;
if (lastDate == null || _isYesterday(lastDate, today)) {
streak += 1;
} else if (!_isSameDay(lastDate, today)) {
streak = 1;
}

await prefs.setInt('streak', streak);
await prefs.setString('lastSessionDate', today.toIso8601String());
await prefs.setInt(
'totalMinutes',
(prefs.getInt('totalMinutes') ?? 0) + minutes,
);
await prefs.setInt(
'totalSessions',
(prefs.getInt('totalSessions') ?? 0) + 1,
);
}
`\

Show the streak on the home screen next to the total minutes, and send one gentle reminder in the morning if the user has not meditated yet. One reminder is enough: a meditation app that nags its users about calm is working against itself. For the same habit-loop thinking in a productivity app, see Build a Pomodoro Focus Timer in Flutter.

How do you keep the interface calm?

A calm interface in a meditation app is a deliberate design decision, not an absence of design. Use a muted palette with one soft accent color, generous spacing, large touch targets, and one action per screen, so the user never has to think about where to tap. The home screen shows the streak, one recommended session, and a play button; the player screen shows the pacer, the session title, and pause. Everything else lives behind a second tap.

Gentle motion helps when it is slow and optional. Short Lottie animations work well for illustrations such as a sunrise or drifting clouds, because they add life without demanding attention. Keep every animation slow, keep the palette quiet, and always honor the reduced-motion setting. The test for a calm interface is simple: open the app at night, in a dark room, and check that nothing on the screen feels loud. If a color, a badge, or an animation pulls the eye, soften it or remove it.

What did building Inhalo teach us?

Inhalo, a Flutter breathing and meditation app, holds a 4.8 star average rating and 62 percent day-30 retention. Those numbers come from the same decisions this guide describes: guided breathing exercises and meditation routines with personalized sessions for stress, anxiety relief and sleep, smooth animations and breathing pacers, audio playback for guided tracks and ambient sounds, and progress tracking that shows users their own habit forming.

Three lessons from building it are worth carrying into your own app. First, the first session must be short and finishable, because a completed first session is what brings a user back for a second. Second, streaks and gentle reminders beat notifications and badges: one morning reminder protects the streak, and the streak protects the habit. Third, the backend can stay simple. Inhalo runs on Flutter and Dart with Firebase behind it and Lottie animations in front, and the app stays focused on the four pieces that matter: sessions, a pacer, audio, and progress. You can see the full case study at Inhalo on uzairxdev.online.

Build the four pieces, keep the interface quiet, and let the streak do the retention work. A meditation app earns its place on a home screen one finished five-minute session at a time.

Get in touch and let's talk about your project.


Originally published at uzairxdev.online

Top comments (0)