Skip to content

Comments

Enhance app type detection logic to include prompt analysis for Flutter references and minor relaxation in system prompts#3560

Open
NamanGoyalK wants to merge 1 commit intodart-lang:mainfrom
NamanGoyalK:fix-issue-3509
Open

Enhance app type detection logic to include prompt analysis for Flutter references and minor relaxation in system prompts#3560
NamanGoyalK wants to merge 1 commit intodart-lang:mainfrom
NamanGoyalK:fix-issue-3509

Conversation

@NamanGoyalK
Copy link

Fixes #3509

This PR addresses the issue where the AI would sometimes incorrectly default to a pure Dart context (CLI/Console) when the user intended to build a Flutter app, particularly when starting from an empty editor.

Changes

  1. pkgs/dartpad_ui/lib/app/genai_editing.dart:

    • Improved the _determineAppType logic to inspect the prompt for keywords (e.g., flutter, widget, app, custompainter) if the source code is ambiguous or empty.
    • This ensures that prompts like "Create a Flutter app" correctly trigger the Flutter system prompt instead of the Dart system prompt.
  2. pkgs/dart_services/lib/src/generative_ai.dart:

    • Adjusted the system prompts to allow the model to deviate from the strict "No UI" or "Flutter Only" rules if and only if the user explicitly and unambiguously requests it.
    • This provides an "escape hatch" for power users who might want to generate a Dart script while in Flutter mode (or vice versa) without the model refusing the request.

Verification

  • Tested locally with prompts such as "Create a Flutter app with a CustomPainter" in an empty editor. The system correctly inferred AppType.flutter and generated the UI code.
  • Verified that ambiguous prompts still default to safe baselines.
image
  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.


final prompt = genAiManager.codeEditPromptController.text.toLowerCase();

bool mentionsFlutter(String p) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated to the issue as far as I can tell, could you take this out or submit this as a separate pull requests? Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, @johnpryan!

​I believe this logic is actually central to fixing the issue. The root cause of #3509 is that an empty editor defaults to AppType.dart, which triggers the "Pure Dart" system prompt (the one forbidding UI).

​This change allows the frontend to detect intent (e.g., "Create a Flutter app") and switch to AppType.flutter before sending the request. This ensures the backend selects the correct flutterPrompt instead of forcing the model to fight against the dartPrompt.

​Without this, we are relying 100% on the relaxed system prompt (the other change in this PR) to override the wrong context. This feels like a more robust fix, but I am happy to split it out if you strictly prefer relying on the prompt change alone.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually @johnpryan , I see where you're coming from regarding PR scope. I've just force-pushed a version that reverts the dartpad_ui changes. Let's keep this PR focused strictly on the system prompt relaxation. I'll move the prompt-based detection logic to a separate discussion/PR. This should be ready for review now!

@github-actions
Copy link

github-actions bot commented Feb 8, 2026

PR Health

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/dart_services/lib/src/context.dart
pkgs/samples/lib/brick_breaker.dart
pkgs/samples/lib/fibonacci.dart
pkgs/samples/lib/hello_world.dart
pkgs/samples/lib/main.dart
pkgs/samples/lib/sunflower.dart

This check can be disabled by tagging the PR with skip-license-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?

This check can be disabled by tagging the PR with skip-breaking-check.

Unused Dependencies ✔️
Package Status
None No packages found to check.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

Coverage ✔️
File Coverage

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to generate a Flutter app with Gemini with empty editor

2 participants