After completing this codelab, students will be able to:
explain the AI-assisted workflow (prompt, generate, verify, test, refactor, explain);
write effective prompts and context for a small Flutter feature;
recognize AI hallucination and limits in Flutter code;
debug and refactor AI-generated code toward Clean Architecture;
test AI-generated code with flutter analyze and tests;
document prompts, AI output, accept/reject decisions, and test evidence in docs/ai-log.md.
Preparation
A laptop/PC and the reviewed Week 5-8 project (for example week5_offline_notes or the Week 7 refactor of campus_notify). This codelab adds one small AI-built feature; it does not start a new project.
Flutter SDK, VS Code (Flutter/Dart extensions), Git, and one AI coding assistant (GitHub Copilot / Cursor / Claude Code / equivalent).
Understanding of Riverpod, repositories, and the Week 7 dependency rule.
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
Area
Example
Stance
Strong
Boilerplate, common patterns, test drafts, docs
Use it, still test
Weak
New APIs, package versions, custom business logic
Verify more
Risky
Auth tokens, SQL queries, security rules
No secrets; write manually
3. Three Flutter hallucination patterns
Fictional method: for example controller.searchFuzzy(). Check IDE autocomplete and pub.dev.
Outdated package: AI uses v1 API while pubspec uses v3. Check pubspec.lock and CHANGELOG.
Confident but wrong: for example a case-sensitive filter hiding a bug. Prove it with one small test.
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
Include: folder structure, one repository/use-case contract, and package versions from pubspec.yaml.
Exclude: tokens, API keys, passwords, or a 500-file repo.
Paste relevant snippets, not blurry screenshots. State what must NOT change.
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
Read every line and mark what you do not understand.
Check imports: keep domain/ free of Flutter/Dio/SQLite.
Check APIs: every method must exist (autocomplete + pub.dev).
Run flutter analyze until zero warnings.
Write at least 1 passing and 1 failing search test.
Test manually: empty query, match, and no-match empty state.
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
At least 1 AI finding proven true (grep/test evidence), then fixed.
At least 1 AI finding rejected with written technical reasons.
Reduce AI output over 80 lines into small testable functions/use cases.
Move filter/search logic from widgets into a pure domain use case.
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
Symptom
Common cause
Fix
Missing method
API hallucination
Check pub.dev + autocomplete
Cross-layer import
Weak context
State limits + refactor
All tests red
Oversized prompt
Ask 1 small feature + 1 test
Repeated prompts
No reproduction
Write steps + red test
Cannot explain
Blind acceptance
Reread + simplify
Self-verification checklist
Five-slot prompt + context in docs/ai-log.md.
flutter analyze clean, flutter test green.
1 AI finding proven true + 1 rejected with reasons.
Able to explain without opening AI.
Mini project / Industry Challenge
Add one small AI-built feature (search/filter/sort) + empty state.
Include the core prompt, pasted context, and initial AI output in docs/ai-log.md.
Green-machine evidence: flutter analyze + flutter test in README.
Accept/reject table with technical reasons + grep/test evidence.
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
Which AI hallucination did you find and how did you prove it?