#!/bin/bash

set -e

flutter doctor -v

declare -ar PROJECT_NAMES=(
    "add_to_app/android_view/flutter_module_using_plugin"
    "add_to_app/books/flutter_module_books"
    "add_to_app/fullscreen/flutter_module"
    "add_to_app/multiple_flutters/multiple_flutters_module"
    "add_to_app/plugin/flutter_module_using_plugin"
    "add_to_app/prebuilt_module/flutter_module"
    "ai_recipe_generation"
    "analysis_defaults"
    "android_splash_screen"
    "animations"
    "asset_transformation"
    "background_isolate_channels"
    "code_sharing/client"
    "code_sharing/server"
    "code_sharing/shared"
    "context_menus"
    "deeplink_store_example"
    "desktop_photo_search/fluent_ui"
    "desktop_photo_search/material"
    "dynamic_theme"
    "experimental/federated_plugin/federated_plugin"
    "experimental/federated_plugin/federated_plugin/example"
    "experimental/federated_plugin/federated_plugin_macos"
    "experimental/federated_plugin/federated_plugin_platform_interface"
    "experimental/federated_plugin/federated_plugin_web"
    "experimental/federated_plugin/federated_plugin_windows"
    "experimental/pedometer"
    "experimental/pedometer/example"
    "experimental/varfont_shader_puzzle"
    "experimental/web_dashboard"
    "flutter_maps_firestore"
    "form_app"
    "game_template"
    "gemini_tasks"
    "google_maps"
    "infinite_list"
    "ios_app_clip"
    "isolate_example"
    "material_3_demo"
    "navigation_and_routing"
    "place_tracker"
    "platform_channels"
    "platform_design"
    "platform_view_swift"
    "provider_counter"
    "provider_shopper"
    "simple_shader"
    "simplistic_calculator"
    "simplistic_editor"
    "testing_app"
    "veggieseasons"
    "web_embedding/element_embedding_demo"
)

echo "--- Running flutter clean and flutter pub get for each sample ---"

for PROJECT_NAME in "${PROJECT_NAMES[@]}"
    do
      echo "== Cleaning '${PROJECT_NAME}' with Flutter clean =="
      pushd "${PROJECT_NAME}"

      # run `flutter clean` for project
      flutter clean

      # Grab packages.
      flutter pub get

      popd
    done

echo "--- Success ---"