Last updated: October 18, 2026

Bahasa Indonesia | English

Learning objectives

After completing this codelab, students will be able to:

Preparation

1. From generate to explain

AI proposes, developers decide:

1. Prompt -> instruction + project context
2. Generate -> AI proposes code
3. Verify -> read, grep, check real APIs
4. Test -> analyze + unit/widget tests
5. Refactor -> align with Clean Architecture
6. Explain -> explain without opening AI

Skipping steps 3-6 is vibe coding: fast at first, expensive later.

2. What AI does well and not

AreaExampleStance
StrongBoilerplate, common patterns, test drafts, docsUse it, still test
WeakNew APIs, package versions, custom business logicVerify more
RiskyAuth tokens, SQL queries, security rulesNo secrets; write manually

3. Three Flutter hallucination patterns

1. Five-slot formula

Role: senior Flutter dev
Context: feature-first, Riverpod, SQLite+Dio
Task: add notes title search + empty state
Limits: keep architecture, max 80 lines
Output: code + 3 test cases + how to test

2. Bad versus good

bad: "make a cool notes search"
good: "Add notes title search.
  Architecture: presentation->domain<-data.
  No SQLite calls from widgets.
  Empty state + 1 widget test."

3. Give context, not secrets

1. Generate one small feature

Ask AI to build notes title search with an empty state. Keep it to one feature for easy verification. Save the raw prompt and AI output in docs/ai-log.md.

2. Six-step verification

3. Example evidence tests

test('filter ignores case', () {
  expect(filterNotes(list, 'groceries'), hasLength(2));
});
test('no-match query returns empty', () {
  expect(filterNotes(list, 'zzz-missing'), isEmpty);
});

1. Debug with a red test

1. Reproduce: steps + input triggering bug
2. Isolate: move filter to pure use case
3. Red test: failing test proving bug
4. Fix small, run tests + analyze
5. Record root cause in docs/ai-log.md

2. Refactor to correct layers

widget (UI only)
  -> notifier (state only)
  -> use case (filter/search rules)
  -> repository (SQLite / Dio)

Split functions over 40 lines and remove database calls from widgets.

3. Final verification

flutter analyze
dart format --set-exit-if-changed .
flutter test
Output: code + 3 test cases + how to test

AI role in this codelab

AI may be a fast generator and initial reviewer, but you decide what to accept, reject, or simplify.

AI Prompt Challenge

Ask AI to review your search code:

Review this Flutter search code as a senior dev.
Context: feature-first (presentation->domain<-data),
Riverpod, SQLite + Dio.
Focus: correctness, architecture, tests. Ignore style.
Give 3 findings + blocker/suggestion level + reasons.

AI Verification Checklist

Refactoring Challenge

  1. Reduce AI output over 80 lines into small testable functions/use cases.
  2. Move filter/search logic from widgets into a pure domain use case.
  3. Remove cross-layer imports and keep analyze clean.

Testing

flutter test test/search_filter_test.dart
# + 1 widget test for empty state
# + manual test of 3 queries + screenshots

Common errors and fixes

SymptomCommon causeFix
Missing methodAPI hallucinationCheck pub.dev + autocomplete
Cross-layer importWeak contextState limits + refactor
All tests redOversized promptAsk 1 small feature + 1 test
Repeated promptsNo reproductionWrite steps + red test
Cannot explainBlind acceptanceReread + simplify

Self-verification checklist

Mini project / Industry Challenge

  1. Add one small AI-built feature (search/filter/sort) + empty state.
  2. Include the core prompt, pasted context, and initial AI output in docs/ai-log.md.
  3. Green-machine evidence: flutter analyze + flutter test in README.
  4. Accept/reject table with technical reasons + grep/test evidence.
  5. Push to 09-week-9-ai-assisted-development/ with docs/, README.md, screenshots/. The README explains the feature, prompt, stack, how to run, and result.

Reflection

Supporting references