FROM ubuntu:22.04

# 设置环境变量
ENV DEBIAN_FRONTEND=noninteractive
ENV FLUTTER_VERSION=3.24.0
ENV FLUTTER_HOME=/flutter
ENV PATH=$PATH:$FLUTTER_HOME/bin

# 安装必要的依赖
RUN apt-get update && apt-get install -y \
    curl \
    git \
    unzip \
    xz-utils \
    zip \
    libglu1-mesa \
    cmake \
    ninja-build \
    pkg-config \
    libgtk-3-dev \
    liblzma-dev \
    libstdc++-12-dev \
    mingw-w64 \
    gcc-mingw-w64 \
    g++-mingw-w64 \
    && rm -rf /var/lib/apt/lists/*

# 下载并安装Flutter
RUN cd /tmp && curl -O https://mirrors-i.tuna.tsinghua.edu.cn/flutter/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}-stable.tar.xz \
    && tar xf flutter_linux_${FLUTTER_VERSION}-stable.tar.xz \
    && ls -la \
    && rm -rf /flutter \
    && mv flutter /flutter \
    && rm flutter_linux_${FLUTTER_VERSION}-stable.tar.xz

# 预下载Flutter依赖
RUN flutter precache

# 修复Git权限问题
RUN git config --global --add safe.directory /flutter

# 设置工作目录
WORKDIR /app

# 复制项目文件
COPY . .

# 获取依赖
RUN flutter pub get

# 构建Windows版本
CMD ["flutter", "build", "windows"]
