This file contains strict instructions for future AI coding assistants working on the AIopoly project. All changes must adhere to these guidelines to ensure consistency, maintainability, and code quality.
AIopoly is a Flutter application that generates Monopoly property names and descriptions based on user-provided themes. It utilizes Google's Gemini API via Firebase Functions or direct calls for content generation.
The project follows a simple, feature-based structure:
lib/data/: Contains data models (create_response.dart,property_group.dart,property.dart) and theServiceclass (service.dart) for API interactions.lib/routes/: Contains screen implementations (home_route.dart,result_route.dart). Files are named with the suffix_route.dart.lib/utils/: Utility functions and constants (e.g.,constants.dartfor logging,hex_color.dartfor color parsing).lib/main.dart: The application entry point and theme configuration.
- Local State: Use
setStatefor managing local widget state (e.g., loading indicators, form validation). - Data Passing: Pass data between screens using constructor arguments.
- Future Features: Incorporate
flutter_blocfor managing complex state and business logic in new features. - Avoid Complexity: For simple features, stick to
setStateand simple prop drilling.
- Navigation: Use
Navigator.of(context)for navigation. - Route Definition: Routes are defined as
StatefulWidgetorStatelessWidgetclasses inlib/routes/. - Pushing Routes: Use
MaterialPageRouteto push new screens onto the stack.Navigator.of(context).push(MaterialPageRoute(builder: (context) { return NextRoute(data: data); }));
- Service Class: All API interactions must be encapsulated within the
Serviceclass inlib/data/service.dart. - Endpoints: The
Serviceclass supports two endpoints:ServiceEndpoint.firebase: Calls a Firebase Cloud Function namedcreate.ServiceEndpoint.direct: specific implementation usingfirebase_aito call Gemini directly (FirebaseAI.googleAI().generativeModel).
- Model Configuration:
- Model:
gemini-2.5-flash-lite - Response MIME Type:
application/json - Schema: Defined using
Schemaobjects to ensure structured JSON output.
- Model:
- Data Models: Use
CreateResponse,PropertyGroup, andPropertyto parse and handle API responses.
- Material 3: The app uses Material 3 (
useMaterial3: trueinThemeData). - Components: Use standard Flutter widgets:
Scaffold,AppBar,Column,Row,ListView,Card,TextField,TextButton,CircularProgressIndicator.- Use
AlertDialog.adaptivefor dialogs.
- Styling: Access colors via
Theme.of(context).colorScheme.- Example:
backgroundColor: Theme.of(context).colorScheme.inversePrimary
- Example:
- User Feedback: Display user-friendly error messages using
AlertDialog.- Catch errors in
onErrorcallbacks ortry-catchblocks.
- Catch errors in
- Logging: Log errors to the console in debug mode using
kDebugModeor the helperdLoginlib/utils/constants.dart. - Graceful Failure: Ensure the UI remains responsive and provides a way to retry or dismiss the error.
- Linter: Follow the rules defined in
analysis_options.yaml, which includesflutter_lints. - Formatting:
- Use 2 spaces for indentation.
- Use trailing commas in widget trees for better readability.
- Ensure all code is formatted using
dart format.
- Imports: Organize imports: Dart core, packages, then project files.
- Widget Tests: Maintain basic widget tests in
test/. - Verification: Before submitting changes, ensure the app compiles and runs without errors.