4.4 KiB
4.4 KiB
PlayMaker — guidance for AI coding assistants
This file gives focused, actionable knowledge to quickly make safe edits in the PlayMaker Flutter app.
Key facts (big picture)
- App: Flutter (mobile + desktop) using Supabase for backend and SharedPreferences for local persistence.
- Data ownership: teams are per-user (teams.user_id). Team records include fields like
id,name,image_url,wins,losses,draws,is_favorite. - Global selection: the app exposes a single global active team via
lib/controllers/active_team.dart— aValueNotifier<ActiveTeam?>namedglobalActiveTeam. UseloadGlobalTeam()andsaveGlobalTeam()to read/update both local (SharedPreferences) and Supabase (profiles.selected_team_id).
Where to look (important files)
lib/controllers/active_team.dart— central logic: load/save active team, prefers favorite team after our recent change.lib/controllers/team_controller.dart— creates teams, toggles favorites and exposesteamsStreamfor realtime listing.lib/pages/home.dart— main UI that shows the selected team, reads/writes last_team_* prefs and usesTeamControllerstreams.lib/pages/status_page.dart— shows detailed stats and accepts initialTeam* props; will use the same persistence keys ashome.dartas a fallback.lib/widgets/*.dart— UI building blocks (game, placar, team widgets) that assume team names/logos are strings and useglobalActiveTeam/selectedTeam state.
Project-specific conventions & patterns
- Single active team: stored locally under prefs keys
last_team_id,last_team_name,last_team_logo,last_team_wins,last_team_losses,last_team_draws. - Realtime lists: controllers expose Streams from Supabase (e.g.,
teamsStream) and UI usesStreamBuilder/snapshot.dataexpecting List<Map<String,dynamic>>. - Favoriting:
teams.is_favoriteis a boolean; code expects at most one favorite per user. When marking favorite, clear other favorites for that user and set the favorite as the global active team (we updatedteam_controller.toggleFavoriteto do this). - Global state: prefer using
globalActiveTeaminstead of ad-hoc SharedPreferences reads when changing the current team — it notifies Home and Status pages automatically. - Naming: Portuguese UI strings are used throughout (e.g., "Selecionar Equipa"), so preserve that when editing visible text.
Examples of common edits
- Changing how the active team is chosen: edit
loadGlobalTeam()inlib/controllers/active_team.dart. Example behaviour implemented: preferteams.is_favorite == true, then fallback toprofiles.selected_team_id, then local prefs. - Adding a field to teams: update Supabase schema, then adapt
TeamController.getTeamsWithStats()and UI widgets underlib/widgets/to read the new field. - Making UI reactive to team changes: call
saveGlobalTeam(ActiveTeam(...))to update memory, Supabase profile and notify UI.
Developer workflows (how to build/test/debug)
- Install dependencies:
flutter pub get. - Run on iOS simulator:
flutter run -d ios(macOS only). Android:flutter run -d android. - Quick analyzer:
flutter analyzeor rely on the project's editor diagnostics. - Running tests: There is a
test/widget_test.dart— runflutter testto execute. - When debugging Supabase flows locally, ensure
google-services.json(Android) and iOS config files are present underandroid/app/andios/as appropriate.
Safe-edit checklist for AI agents
- Prefer small, focused patches. Keep existing structure and naming conventions (Portuguese strings,
prefskeys and Supabase table names). - When touching team selection: update both local prefs and Supabase
profiles.selected_team_id(usesaveGlobalTeam). - When changing persistence keys, update both
home.dartandstatus_page.dartandactive_team.dart. - Avoid altering app-wide themes or widget contracts unless necessary; many widgets rely on team names/logos being non-null strings.
- If adding Supabase queries, filter by
user_idunless deliberately global.
If you can't find something
- Search for the pref keys
last_team_id/last_team_name/last_team_logoto locate all usages. - Look for
globalActiveTeamto see places that react to the active team.
Contact / next steps
- After applying changes that affect team selection flow, run
flutter analyzeand (if possible)flutter test. - Ask for confirmation before changing user-visible Portuguese copy or database schema.
— end of guidance —