# Rebuild Flutter Web App and Restart Server $ErrorActionPreference = "Stop" Write-Host "========================================" -ForegroundColor Cyan Write-Host "Rebuilding Flutter Web App" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan # Kill Flutter web server on port 8081 Write-Host "[1/3] Stopping Flutter web server..." -ForegroundColor Yellow $flutterPid = Get-NetTCPConnection -LocalPort 8081 -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty OwningProcess if ($flutterPid) { Stop-Process -Id $flutterPid -Force Start-Sleep -Seconds 2 Write-Host " [OK] Flutter web server stopped" -ForegroundColor Green } else { Write-Host " [SKIP] No Flutter web server running" -ForegroundColor Gray } # Rebuild Flutter web app Write-Host "[2/3] Rebuilding Flutter web app..." -ForegroundColor Yellow cd C:\DEV\COPILOT\geutebruck_app # Refresh PATH to find flutter $env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'User') # Find flutter executable $flutterExe = Get-Command flutter -ErrorAction SilentlyContinue if (-not $flutterExe) { Write-Host " [ERROR] Flutter not found in PATH!" -ForegroundColor Red Write-Host " Looking for Flutter in common locations..." -ForegroundColor Yellow # Common Flutter locations on Windows $possiblePaths = @( "$env:USERPROFILE\flutter\bin\flutter.bat", "C:\flutter\bin\flutter.bat", "C:\src\flutter\bin\flutter.bat" ) foreach ($path in $possiblePaths) { if (Test-Path $path) { Write-Host " [FOUND] Flutter at: $path" -ForegroundColor Green $flutterExe = $path break } } if (-not $flutterExe) { Write-Host " [ERROR] Could not find Flutter! Please install Flutter or add it to PATH." -ForegroundColor Red exit 1 } } Write-Host " Using Flutter: $($flutterExe.Source)" -ForegroundColor Cyan # Run flutter build & $flutterExe build web --release if ($LASTEXITCODE -eq 0) { Write-Host " [OK] Flutter web app built successfully" -ForegroundColor Green } else { Write-Host " [ERROR] Flutter build failed with exit code $LASTEXITCODE" -ForegroundColor Red exit 1 } # Start Flutter web server Write-Host "[3/3] Starting Flutter web server..." -ForegroundColor Yellow Start-Process -FilePath "python" ` -ArgumentList "-m", "http.server", "8081", "--bind", "0.0.0.0" ` -WorkingDirectory "C:\DEV\COPILOT\geutebruck_app\build\web" ` -WindowStyle Hidden Start-Sleep -Seconds 3 $newPid = Get-NetTCPConnection -LocalPort 8081 -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty OwningProcess if ($newPid) { Write-Host " [OK] Flutter web server started (PID: $newPid)" -ForegroundColor Green } else { Write-Host " [ERROR] Failed to start Flutter web server" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "========================================" -ForegroundColor Green Write-Host "Rebuild Complete!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "" Write-Host "Flutter Web: http://localhost:8081" -ForegroundColor Cyan Write-Host "Please refresh your browser (Ctrl+Shift+R) to see changes" -ForegroundColor Yellow Write-Host ""