LAB 4 — Navigation, ViewModel & App Architecture ================================================= Mobile Application Development | SUZA | Semester II 2025/2026 OBJECTIVES ---------- - Set up Navigation-Compose with NavHost / NavController - Pass arguments between screens - Introduce ViewModel with StateFlow - Apply unidirectional data flow (UDF) SETUP ----- In your app's build.gradle.kts (Module): implementation("androidx.navigation:navigation-compose:2.7.7") implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0") EXERCISES --------- 1. Two-Screen Hello App - HomeScreen: a TextField for name + "Greet" button - GreetingScreen: shows "Hello, !" and a "Back" button - Pass the name as a route argument: navController.navigate("greeting/$name") - Route: "greeting/{name}" 2. Cupcake Order (simplified) Build an ordering flow with 4 screens: a. StartOrderScreen — choose quantity (1, 6, 12) b. FlavorScreen — pick flavour from radio buttons c. PickupScreen — pick a date (3 options: today, tomorrow, in 3 days) d. SummaryScreen — show quantity, flavour, date, price; "Send" button launches a share Intent (ACTION_SEND) Use a single OrderViewModel holding StateFlow. Each screen reads/updates the shared ViewModel. 3. Scaffold + TopAppBar with Back In Cupcake, every screen except Start has a back arrow in the TopAppBar that calls navController.navigateUp(). 4. Settings Sub-Flow - Add a "Settings" FAB on HomeScreen - Navigate to SettingsScreen with a theme toggle (light/dark) - Apply the chosen theme to the whole app (hoist to root via ViewModel) REQUIREMENTS ------------ - Package structure: ui/ (composables, screens) ui/theme/ viewmodel/ data/ (model classes, enums) - Every Composable screen must be previewable independently using hoisted parameters — do NOT call viewModel() inside the screen if it would prevent previews. DISCUSSION (NOTES.md) --------------------- - Why does Compose recommend a single-Activity architecture? - What does "unidirectional data flow" mean in your Cupcake flow? - How does ViewModel help with screen rotation? DELIVERABLES ------------ - Project "CupcakeApp" pushed to GitHub as "mad-lab04" - Screenshots of all 4 Cupcake screens + Settings - NOTES.md with answers to discussion