#!/usr/bin/env bash
set -e
FLUTTER_DIR="$HOME/flutter"
FLUTTER_REPO="https://github.com/flutter/flutter.git"
FLUTTER_CHANNEL="stable"
FLUTTER_BIN="$FLUTTER_DIR/bin"
GREEN="\033[0;32m"
NC="\033[0m"
echo -e "${GREEN}▶️ Installing Flutter ($FLUTTER_CHANNEL channel)...${NC}"
if [ ! -d "$FLUTTER_DIR" ]; then
    echo -e "${GREEN}📦 Cloning Flutter repository...${NC}"
    git clone -b $FLUTTER_CHANNEL "$FLUTTER_REPO" "$FLUTTER_DIR"
else
    echo -e "${GREEN}🔄 Flutter already installed at $FLUTTER_DIR, pulling latest...${NC}"
    git -C "$FLUTTER_DIR" pull
fi
"$FLUTTER_BIN/flutter" --version
echo -e "${GREEN}✅ Flutter installed successfully.${NC}"
echo ""
echo "🔧 Add the following to your shell config (e.g., ~/.bashrc, ~/.zshrc):"
echo ""
echo "    export PATH=\"\$HOME/flutter/bin:\$PATH\""
echo ""
echo -e "${GREEN}🚀 Then restart your shell or run: source ~/.bashrc (or ~/.zshrc)${NC}"
