A bubble shooter looks simple: aim, shoot, match three bubbles of the same color, and watch the cluster pop. The hard parts hide underneath. Bubbles sit on a staggered hex grid, a shot bounces off walls and must stop in exactly the right cell, a match floods through neighbors, and bubbles left hanging after a pop have to fall. Get one detail wrong and the game feels unfair within a minute.

This guide builds a Flutter bubble shooter step by step, using the design behind Bubble Shooter: Bubble Pop, a relaxing puzzle game with 100 levels across four worlds, boosters, an endless mode, and symbol bubbles that color-blind players can tell apart by shape as well as color.

How should you model the bubble grid in Flutter?

Model the board as rows of cells on an offset hex grid, where every second row shifts by half a bubble diameter so each bubble touches six neighbors. Store the board as a list of rows of nullable colors, where null means empty. A board with 10 columns and a radius of 18 logical pixels fits most phones, and the row height is the radius multiplied by 1.732, the vertical spacing of hex packing. Keeping the board as plain data, separate from widgets, makes matching and level loading simple functions over lists.

import 'dart:math' as math; enum BubbleColor { coral, teal, amber, violet, green, blue } class BubbleGrid { BubbleGrid({required this.columns, required this.radius}) : rows = <List<BubbleColor?>>[]; final int columns; final double radius; final List<List<BubbleColor?>> rows; double get rowHeight => radius * 1.732; double get boardWidth => columns * radius * 2; Offset centerOf(int row, int col) { final offsetX = row.isOdd ? radius : 0.0; return Offset( offsetX + col * radius * 2 + radius, row * rowHeight + radius, ); } bool inBounds(int row, int col) => row >= 0 && row < rows.length && col >= 0 && col < columns; BubbleColor? at(int row, int col) => inBounds(row, col) ? rows[row][col] : null; } 

Decide the offset rule once, in one centerOf function, and let neighbors, collision, and rendering all read centers from it, so shots never land half a bubble away from the aim. Separating rules from widgets follows the repository pattern guide.

How does aiming with wall bounces work?

Aiming converts the drag position into an angle, then simulates a ray from the shooter that reflects off the side walls until it reaches the cluster. Compute the angle with atan2 and clamp it between 15 and 165 degrees so the player cannot aim downward. Step the ray forward in small increments, flip the horizontal direction at each wall, and stop within one diameter of a placed bubble or at the ceiling. The stopping point becomes the ghost bubble, showing exactly where the shot will land.

AimResult traceAim({ required Offset origin, required double angleRadians, required BubbleGrid grid, required double boardTop, }) { var direction = Offset(math.cos(angleRadians), -math.sin(angleRadians)); var point = origin; final path = <Offset>[point]; final step = grid.radius * 0.5; final leftWall = grid.radius; final rightWall = grid.boardWidth - grid.radius; for (var i = 0; i < 400; i++) { point += direction * step; if (point.dx <= leftWall || point.dx >= rightWall) { direction = Offset(-direction.dx, direction.dy); point = Offset(point.dx.clamp(leftWall, rightWall), point.dy); path.add(point); } if (point.dy <= boardTop + grid.radius) break; if (_hitsBubble(point, grid)) break; } path.add(point); return AimResult(path, point); } 

Draw the preview as a dashed line with a translucent ghost bubble at the landing point, using the same simulation for preview and shot so they never mismatch. The CustomPainter documentation covers the canvas drawing.

How do you detect collision and snap a shot to the grid?

Collision checks the distance between the flying bubble and every placed bubble, and the shot stops when that distance falls below two radii, meaning the circles touch. Then snap the shot to the empty cell closest to it among the neighbors of the bubble that was hit, or the top row when the shot reaches the ceiling. Restricting the snap to legal neighbors prevents tunneling into pockets the shot could never reach. Advance the shot in steps of at most half a radius per frame so it cannot jump past a bubble between frames.

(int, int)? snapCell(BubbleGrid grid, Offset shot, int hitRow, int hitCol) { (int, int)? best; var bestDistance = double.infinity; for (final (r, c) in neighborsOf(hitRow, hitCol)) { if (!grid.inBounds(r, c) || grid.at(r, c) != null) continue; final d = (grid.centerOf(r, c) - shot).distance; if (d < bestDistance) { bestDistance = d; best = (r, c); } } return best; } List<(int, int)> neighborsOf(int row, int col) { final shift = row.isOdd ? 1 : -1; return [ (row, col - 1), (row, col + 1), (row - 1, col), (row - 1, col + shift), (row + 1, col), (row + 1, col + shift), ]; } 

Neighbor offsets depend on row parity. Write neighborsOf once and reuse it for snapping, matching, and falling checks, so a bubble never lands where the matcher sees no connection. Drive movement with a ticker; the Flutter animations guide covers the basics.

How do you find matches of three or more bubbles?

Match detection flood-fills from the newly placed bubble through same-color neighbors, and the connected group pops when it holds three or more bubbles. Use a queue plus a visited set of (row, col) records, which hash and compare by value in Dart. Run the check only from the placed bubble, because only the new bubble can create a new match, keeping the cost proportional to one cluster instead of the whole board.

List<(int, int)> findMatch(BubbleGrid grid, int startRow, int startCol) { final color = grid.at(startRow, startCol); if (color == null) return const []; final visited = <(int, int)>{}; final queue = <(int, int)>[(startRow, startCol)]; final group = <(int, int)>[]; while (queue.isNotEmpty) { final cell = queue.removeLast(); if (!visited.add(cell)) continue; if (grid.at(cell.$1, cell.$2) != color) continue; group.add(cell); queue.addAll(neighborsOf(cell.$1, cell.$2)); } return group.length >= 3 ? group : const []; } 

When the group pops, remove those cells, play a scale-and-fade animation, then run the falling check. Score per popped bubble, with dropped bubbles scoring double, so disconnecting a hanging cluster beats a plain three-match.

How do you drop bubbles that are no longer connected?

Falling bubbles are found by marking every bubble still connected to the top row, then dropping every bubble the marking pass never reached. Flood-fill from every occupied cell in row zero, following neighbors of any color, and collect the reachable set. Any occupied cell outside that set hangs in the air and should fall. Run this pass after every pop, because a pop is the only event that can disconnect a cluster.

List<(int, int)> findFloating(BubbleGrid grid) { final anchored = <(int, int)>{}; final queue = <(int, int)>[ for (var c = 0; c < grid.columns; c++) if (grid.at(0, c) != null) (0, c), ]; while (queue.isNotEmpty) { final cell = queue.removeLast(); if (!anchored.add(cell)) continue; for (final n in neighborsOf(cell.$1, cell.$2)) { if (grid.at(n.$1, n.$2) != null) queue.add(n); } } return [ for (var r = 0; r < grid.rows.length; r++) for (var c = 0; c < grid.columns; c++) if (grid.at(r, c) != null && !anchored.contains((r, c))) (r, c), ]; } 

Animate drops with an accelerating fall, distinct from the pop, and lock input until both animations finish.

How do you render the board without jank?

Render with one CustomPainter drawing every bubble, the preview, and the flying bubble in a single pass, instead of one widget per bubble. Drive the loop with a Ticker, wrap the surface in a RepaintBoundary, and precompute gradients outside paint.

Approach Frame cost Best for
One widget per bubble High, layout and paint per bubble Prototypes with tiny boards
Single CustomPainter Low, one paint pass for all bubbles Production games
Flame engine Low, with a full game loop Larger games with sprites and physics

One painter plus a ticker covers the whole game without an engine. Keep per-frame work small, as in the Flutter isolates guide.

How do you design levels, scoring and boosters?

Design levels as data: starting rows, colors, and a shot limit. Bubble Shooter: Bubble Pop ships 100 levels across four worlds — Lagoon Shallows, Coral Reef, Deep Blue and Sunken Temple — with three-star ratings, limited shots, and +100 points per unused shot. Three-star finishes earn boosters: Bomb, Fireball, and Rainbow.

class LevelDef { const LevelDef({ required this.id, required this.rows, required this.colors, required this.shotLimit, }); final int id; final List<String> rows; // one character per cell, dot for empty final List<BubbleColor> colors; final int shotLimit; } const levelOne = LevelDef( id: 1, colors: [BubbleColor.coral, BubbleColor.teal, BubbleColor.amber], shotLimit: 12, rows: ['cccttaacc', '.ccttaa', 'tttaaccc'], ); 

Encode rows as strings so levels stay readable, draw the next shooter bubble only from colors still on the board, and save progress on-device with no account needed. An endless mode drops a new row after a few misses on Easy, Medium and Hard.

How do you make bubbles readable for color-blind players?

Draw a unique symbol inside every bubble — a star, circle, triangle, or diamond — so players match by shape as well as color. Bubble Shooter: Bubble Pop gives every bubble its own symbol alongside its color, supporting deuteranopia, protanopia and tritanopia, with symbols on by default and a Settings switch to turn them off. Symbols cost almost nothing, because the painter draws one small precomputed path per bubble. Color carries the theme; shape carries the information. The full approach is covered in color-blind friendly games in Flutter.

Add reduce-motion settings, separate haptics, sound and music controls, and no timers in the main levels. The same fair-touch thinking shapes the arrow puzzle game guide.

What mistakes break a first bubble shooter?

The common mistakes are a square-grid neighbor table on a hex board, a preview that differs from the real shot, and collision steps large enough to tunnel through bubbles. Each produces a specific symptom, which makes debugging fast once the symptoms are named.

Symptom Likely cause Fix
Matches of three do not pop Neighbor offsets ignore row parity Use one parity-aware neighbor function everywhere
Shot lands away from the ghost bubble Preview and shot use different simulations Share one trace function for both
Bubble passes through the cluster Frame step larger than a radius Step at most half a radius per update
Hanging bubbles stay in the air Falling check runs before the pop finishes Run the anchored pass after removing the match
Player receives unmatchable colors Shooter queue ignores board colors Draw the next bubble from colors still on the board
Board repaints the whole screen No repaint boundary around the game Wrap the game surface in a RepaintBoundary

Test the pure logic first: unit tests can assert pop and drop results in milliseconds. Cover a match crossing row parity, a drop disconnecting a two-color cluster, and a snap next to the left wall.

Putting the game together

A complete game needs six pieces in agreement: a hex grid with one center function, a shared neighbor table, a reflecting aim trace, snapping collision, a flood-fill match check, and an anchored falling pass. Build the pure logic first, test it, then add aiming, animation, and levels.

If you are planning a puzzle game with this level of polish, from grid logic to accessibility and level design, I build exactly this kind of experience in Flutter. Get in touch and let's talk about your project.

Originally published at uzairxdev.online