build static method

String build(
  1. String sourceCode,
  2. String filePath,
  3. List<UiElement>? uiElements
)

Implementation

static String build(String sourceCode, String filePath, List<UiElement>? uiElements) {
  final uiContext = uiElements != null && uiElements.isNotEmpty
      ? '\nDetected UI Elements (make sure to interact with or verify these):\n${uiElements.map((e) => '- $e').join('\n')}'
      : '';

  return '''
You are an elite senior Flutter developer and testing expert.
Your task is to write a COMPLETE, fully-implemented, production-ready Dart test file for the following Flutter source code.

File Path of Source: $filePath

Source Code:
```dart
$sourceCode
```$uiContext

Requirements:
1. ONLY return the final Dart test code inside a single ```dart ... ``` markdown block. Do NOT include any explanations.
2. The code MUST compile and follow the AAA pattern (Arrange, Act, Assert).
3. Do NOT generate empty test stubs (e.g. `// TODO:`). Write the ACTUAL logic.
4. If it's a Widget (Stateless/Stateful), use `testWidgets`, wrap with `MaterialApp`, write `pumpWidget`.
5. For widgets, detect buttons and text fields from the UI context and generate tap interactions and input testing.
6. If it's a Service, Repository, Controller, BLoC, or Cubit, fully implement every method test.
7. Generate ALL necessary mocks inline using `package:mocktail`.
8. Import `package:flutter_test/flutter_test.dart`.

Generate the test file now:
''';
}