Gift Grab is a Christmas arcade game for Flutter: steer Santa around the screen with a joystick, grab as many falling gifts as you can in 30 seconds, and post your score to a monthly leaderboard you share with friends and groups. This repo is the client app: sign-in, menus, leaderboard and social features wrapped around the game itself, which lives in the separate gift_grab_game package. Everything online runs on a Nakama server (gift_grab_server).
The game (from gift_grab_game, launched by the client at /main/game)
- 30-second rounds. Each gift Santa touches is a point, and the timer and score sit in the HUD.
- Ice freezes Santa in place for a moment.
- Flames give Santa 10 seconds of protection, so ice can't freeze him.
- Cookies give a short speed boost.
- When a round ends, the score is written to the
monthly_leaderboardand a game-over overlay lets you play again.
The app around it
- Sign-in through Clerk's prebuilt auth UI. The Clerk session JWT is exchanged for a Nakama session (
authenticateCustom), and new Clerk users get a Nakama account created on first login. - Main menu greets you by username and links to Play, Profile, Leaderboard, Friends and Groups, plus user search and Settings.
- Leaderboard pages through the monthly leaderboard, 10 records at a time.
- Profiles show a player's details. On someone else's profile a single button follows your friendship state with them: send, cancel, accept or reject a request, remove a friend, block or unblock. A blocked user's profile is hidden. You can edit your own username.
- Friends has four tabs: Friends, Invites, Requests and Blocked.
- Groups has "All Groups" and "My Groups" tabs, group search, and create and edit forms (name, description, open or closed). Members can join, leave or cancel a pending request. Admins can add, kick, ban, promote and demote members from a bottom sheet.
- Profanity check: usernames and group names and descriptions are scanned with
profanity_apibefore saving. - Settings shows the app version and licenses, and lets you log out or delete your account (through a server RPC).
- Analytics: PostHog tracks screen views (
PosthogObserveron the router), identifies users at login, logsUser Played Gamewith the score andUser Logged Out, and captures Flutter, isolate and native errors. - Over-the-air patches with Shorebird (
shorebird.yaml).
Clerk sign-in ──JWT──▶ AuthController ──authenticateCustom──▶ Nakama session
│
SessionService ◀────────┘
(Hive box, auto-refresh 5 min before expiry)
│
BLoCs / controllers ──session──▶ Nakama client (leaderboards, friends, groups, RPCs)
- Startup (
lib/main.dart): sets up the Nakama client and Hive, wraps the app inClerkAuth, thenAppInitializerregisters dependencies, builds the router, and shows a Lottie loader until everything is ready. - Dependency injection (
lib/core/di_container.dart):get_itregistersPostHogService,ClerkAuthState,ModalService,SessionService,GroupService, and signal-based controllers (AuthController,AccountReadController, and per-group member controllers). - State: each feature is a BLoC with sealed events and
Equatablestates, usingbloc_error_handler'srunWithErrorHandling(). Most were scaffolded with theflutter_bloc_featureMason brick. Auth, account and group-member state usesignals(AsyncSignal) instead. - Routing (
lib/data/configuration/app_routes.dart): GoRouter with every screen nested under/main. The router refreshes whenAuthController.isAuthenticatedchanges and redirects to/loginwhen you're signed out. AShellRouteshows Clerk errors as toasts. - Server calls: mostly standard Nakama APIs, plus four custom RPCs in
lib/data/enums/rpc_functions.dart:account_delete_id,get_friendship_state,get_group_by_idandget_group_membership_state. These must exist on the server. - UI:
shadcn_uithemes the app (dark mode, ABeeZee font from Google Fonts). Shared widgets such asGGScaffoldWidget,MenuButtonWidgetandFlexGridviewWidgetcome from thegift_grab_uipackage.
- Flutter, Dart SDK
>=3.12.0 <4.0.0 - Game:
gift_grab_game(Flame engine, git dependency) - UI:
gift_grab_ui(git dependency),shadcn_ui,google_fonts,lottie,settings_ui,font_awesome_flutter - State:
flutter_bloc,bloc_error_handler,signals,equatable,formz(form validation) - Navigation:
go_router - Backend:
nakama - Auth:
clerk_flutter(beta).google_sign_inandsign_in_with_appleare also dependencies. - Storage:
hive/hive_flutter(session tokens) - Analytics:
posthog_flutter - Other:
get_it,result_dart,profanity_api,package_info_plus,window_manager(desktop window sizing),logger - Testing:
flutter_test,bloc_test,mocktail - Releases: Shorebird code push
- A Flutter SDK whose Dart version satisfies
>=3.12.0 - Git access to
trey-a-hope/gift_grab_gameandtrey-a-hope/gift_grab_ui(both public, pulled byflutter pub get) - A running Nakama server with the Gift Grab modules (
gift_grab_server), meaning themonthly_leaderboardleaderboard and the four RPCs above - Optional: the Shorebird CLI for releases and patches
git clone https://github.com/trey-a-hope/gift_grab_client.git
cd gift_grab_client
flutter pub getThe environment comes from the build mode, not from a flag you set (lib/data/configuration/environment.dart):
| Debug and profile builds | Release builds | |
|---|---|---|
| Nakama host | 127.0.0.1 |
gift-grab-server.app |
| Clerk key | test key (pk_test_…) |
live key (pk_live_…) |
Other settings in lib/data/constants/globals.dart:
- Nakama uses server key
defaultkeyand HTTP port443in both environments. SSL is only on for web builds. So a local Nakama server has to listen on127.0.0.1:443, or you need to changenakamaClientHttpPort(Nakama's default is7350). - Page sizes:
recordListLimit10,friendListLimit15,groupListLimit10. - The PostHog project token and US host are in
lib/domain/services/post_hog_service.dart.
The VS Code launch configs (.vscode/launch.json) pass --dart-define-from-file=./env/local.json. env/example_prod.json shows the expected shape, which is one FLUO_API_KEY. That key is currently not read: the code that reads it in main.dart is commented out, left over from an earlier auth provider.
flutter devices
flutter run -d <device_id>
# same as the VS Code "debug" config:
flutter run --dart-define-from-file=./env/local.jsonThere are platform folders for Android, iOS, web, macOS, Windows and Linux. A note in pubspec.yaml says Clerk doesn't support web yet (clerk-sdk-flutter#302), so sign-in won't work in the browser for now.
Unit tests cover the event, state and bloc of each feature BLoC, in test/blocs/<feature>/bloc/. There are 15 features, using bloc_test and mocktail, with shared mocks in test/test_helper.dart. test/widget_test.dart is a basic smoke test.
flutter test
flutter test --coverage
flutter analyzemason.yaml also includes the flutter_coverage_updater brick for generating coverage reports.
The version format is YY.M.D+build, for example 26.7.3+82 in pubspec.yaml. Store release notes go in release_notes.json. With Shorebird:
shorebird release android # or ios
shorebird patch android # push a Dart-only fix to existing installslib/
├── main.dart # bootstrap: Nakama client, Hive, ClerkAuth, theme
├── core/ # get_it container, logger
├── data/
│ ├── configuration/ # app_routes.dart, environment.dart, gap sizes, signal observer
│ ├── constants/ # globals, label text, feedback messages
│ ├── enums/ # GoRoutes, Leaderboards, RpcFunctions
│ └── repositories/ # SessionRepository (Hive)
├── domain/
│ ├── entities/ # LeaderboardEntry
│ ├── repositories/ # ISessionRepository
│ └── services/ # SessionService, GroupService, PostHogService
├── presentation/
│ ├── blocs/ # one folder per feature: bloc/ + view/
│ ├── controllers/ # signal-based auth, account and group-member controllers
│ ├── cubits/ # GroupRefreshCubit
│ ├── pages/ # login, main menu, settings, group/*
│ ├── services/ # ModalService (toasts, dialogs)
│ ├── extensions/
│ └── widgets/
└── util/ # desktop window setup
assets/ # images and audio the game package loads, plus the app icon
test/blocs/ # BLoC unit tests
flutter_packages_json/ # package lists grouped by course module (setup, auth, users, leaderboards)
- Sign-in doesn't work on web until Clerk adds web support (see above).
main.darthas a TODO to add a timeout to the Clerk auth request.- Debug builds point at
127.0.0.1on port 443, so testing against a local server needs that port or a code change. PostHogServiceruns withdebug = truein every build.