#!/bin/bash
set -e

function build_all() {
    echo "1. Build Web"
    flutter build web --dart-define=FLUTTER_WEB_USE_EXPERIMENTAL_CANVAS_TEXT=true --web-renderer html
    echo "2.1 Build Android APK"
    flutter build apk --release --verbose
    echo "2.2 Build Android APK"
    flutter build apk --split-per-abi
    echo "2.3 Build Android AppBundle"
    flutter build appbundle
    echo "3. Build iOS"
    flutter build ios --release
    echo "All done!"
    exit
}

function build_web() {
    echo "<<< Build Web >>>"
    flutter build web --dart-define=FLUTTER_WEB_USE_EXPERIMENTAL_CANVAS_TEXT=true --web-renderer html
    echo "Done!"
    exit
}

function build_android() {
    echo "1 Build Android APK"
    flutter build apk --release --verbose
    echo "2 Build Android APK"
    flutter build apk --split-per-abi
    echo "3 Build Android AppBundle"
    flutter build appbundle
    echo "Done!"
    exit
}

function build_ios() {
    echo "<<< Build iOS >>>"
    flutter build ios --release
    echo "Done!"
}

PS3='Please choice: '
options=("Build All" "Build Web" "Build Android" "Build iOS")
select opt in "${options[@]}"; do
    case $opt in
    "Build All")
      build_all
      ;;
    "Build Web")
      build_web
      ;;
    "Build Android")
      build_android
      ;;
    "Build iOS")
      build_ios
      ;;
    *) echo "Invalid option $REPLY";;
    esac
done