-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlutter_install.ps1
More file actions
185 lines (155 loc) · 7.55 KB
/
Flutter_install.ps1
File metadata and controls
185 lines (155 loc) · 7.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Flutter Installation Script for Windows
# Run this script as Administrator for best results
param(
[Parameter(Mandatory=$true)]
[string]$FlutterZipPath,
[string]$InstallPath = "C:\flutter",
[switch]$SkipAndroidStudio,
[switch]$SkipVisualStudio
)
Write-Host "=== Flutter Installation Script ===" -ForegroundColor Green
Write-Host "Flutter ZIP: $FlutterZipPath" -ForegroundColor Yellow
Write-Host "Install Path: $InstallPath" -ForegroundColor Yellow
# Check if running as administrator
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Warning "Not running as Administrator. Some operations may fail."
}
# Function to add to PATH
function Add-ToPath {
param([string]$PathToAdd)
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($currentPath -notlike "*$PathToAdd*") {
$newPath = "$currentPath;$PathToAdd"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
Write-Host "Added $PathToAdd to PATH" -ForegroundColor Green
# Update current session PATH
$env:PATH += ";$PathToAdd"
} else {
Write-Host "$PathToAdd already in PATH" -ForegroundColor Yellow
}
}
# Function to check if command exists
function Test-Command {
param([string]$Command)
try {
Get-Command $Command -ErrorAction Stop | Out-Null
return $true
} catch {
return $false
}
}
# Step 1: Extract Flutter
Write-Host "`n=== Step 1: Extracting Flutter ===" -ForegroundColor Cyan
if (-not (Test-Path $FlutterZipPath)) {
Write-Error "Flutter ZIP file not found at: $FlutterZipPath"
exit 1
}
if (Test-Path $InstallPath) {
Write-Host "Flutter directory already exists. Removing..." -ForegroundColor Yellow
Remove-Item $InstallPath -Recurse -Force
}
Write-Host "Extracting Flutter to $InstallPath..." -ForegroundColor White
try {
Expand-Archive -Path $FlutterZipPath -DestinationPath (Split-Path $InstallPath -Parent) -Force
Write-Host "Flutter extracted successfully!" -ForegroundColor Green
} catch {
Write-Error "Failed to extract Flutter: $_"
exit 1
}
# Step 2: Add Flutter to PATH
Write-Host "`n=== Step 2: Adding Flutter to PATH ===" -ForegroundColor Cyan
$flutterBinPath = Join-Path $InstallPath "bin"
Add-ToPath $flutterBinPath
# Step 3: Install Git (if not present)
Write-Host "`n=== Step 3: Checking Git Installation ===" -ForegroundColor Cyan
if (-not (Test-Command "git")) {
Write-Host "Git not found. Installing Git..." -ForegroundColor Yellow
if (Test-Command "winget") {
winget install --id Git.Git -e --source winget
} elseif (Test-Command "choco") {
choco install git -y
} else {
Write-Warning "Please install Git manually from https://git-scm.com/download/win"
Write-Host "After installing Git, restart this script." -ForegroundColor Yellow
}
} else {
Write-Host "Git is already installed" -ForegroundColor Green
}
# Step 4: Install Android Studio (optional)
if (-not $SkipAndroidStudio) {
Write-Host "`n=== Step 4: Installing Android Studio ===" -ForegroundColor Cyan
if (Test-Command "winget") {
Write-Host "Installing Android Studio via winget..." -ForegroundColor White
winget install --id Google.AndroidStudio -e --source winget
} elseif (Test-Command "choco") {
Write-Host "Installing Android Studio via Chocolatey..." -ForegroundColor White
choco install androidstudio -y
} else {
Write-Warning "Package manager not found. Please install Android Studio manually:"
Write-Host "Download from: https://developer.android.com/studio" -ForegroundColor Yellow
}
} else {
Write-Host "`n=== Step 4: Skipping Android Studio ===" -ForegroundColor Yellow
}
# Step 5: Install Visual Studio (for Windows development)
if (-not $SkipVisualStudio) {
Write-Host "`n=== Step 5: Installing Visual Studio Build Tools ===" -ForegroundColor Cyan
if (Test-Command "winget") {
Write-Host "Installing Visual Studio Build Tools..." -ForegroundColor White
winget install --id Microsoft.VisualStudio.2022.BuildTools -e --source winget
} elseif (Test-Command "choco") {
Write-Host "Installing Visual Studio Build Tools via Chocolatey..." -ForegroundColor White
choco install visualstudio2022buildtools -y
} else {
Write-Warning "Package manager not found. Please install Visual Studio manually:"
Write-Host "Download from: https://visualstudio.microsoft.com/downloads/" -ForegroundColor Yellow
}
} else {
Write-Host "`n=== Step 5: Skipping Visual Studio ===" -ForegroundColor Yellow
}
# Step 6: Install Chrome (for web development)
Write-Host "`n=== Step 6: Checking Chrome Installation ===" -ForegroundColor Cyan
$chromeInstalled = Test-Path "C:\Program Files\Google\Chrome\Application\chrome.exe" -or
Test-Path "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
if (-not $chromeInstalled) {
Write-Host "Chrome not found. Installing Chrome..." -ForegroundColor Yellow
if (Test-Command "winget") {
winget install --id Google.Chrome -e --source winget
} elseif (Test-Command "choco") {
choco install googlechrome -y
} else {
Write-Warning "Please install Chrome manually from https://www.google.com/chrome/"
}
} else {
Write-Host "Chrome is already installed" -ForegroundColor Green
}
# Step 7: Run Flutter Doctor
Write-Host "`n=== Step 7: Running Flutter Doctor ===" -ForegroundColor Cyan
Write-Host "Checking Flutter installation..." -ForegroundColor White
# Refresh environment variables
$env:PATH = [Environment]::GetEnvironmentVariable("PATH", "User") + ";" + [Environment]::GetEnvironmentVariable("PATH", "Machine")
try {
& "$flutterBinPath\flutter.bat" doctor
} catch {
Write-Warning "Flutter doctor failed to run. You may need to restart your terminal."
Write-Host "Try running 'flutter doctor' manually after restarting." -ForegroundColor Yellow
}
# Step 8: Accept Android licenses (if Android Studio was installed)
if (-not $SkipAndroidStudio) {
Write-Host "`n=== Step 8: Android License Setup ===" -ForegroundColor Cyan
Write-Host "To accept Android licenses, run the following command after Android Studio setup:" -ForegroundColor Yellow
Write-Host "flutter doctor --android-licenses" -ForegroundColor White
}
Write-Host "`n=== Flutter Installation Complete! ===" -ForegroundColor Green
Write-Host "Next steps:" -ForegroundColor White
Write-Host "1. Restart your terminal or VS Code" -ForegroundColor White
Write-Host "2. Run 'flutter doctor' to verify installation" -ForegroundColor White
Write-Host "3. If using Android: Set up Android SDK in Android Studio" -ForegroundColor White
Write-Host "4. Run 'flutter doctor --android-licenses' to accept Android licenses" -ForegroundColor White
Write-Host "5. Create your first Flutter app: 'flutter create my_app'" -ForegroundColor White
Write-Host "`nUseful Flutter commands:" -ForegroundColor Cyan
Write-Host "flutter doctor - Check installation" -ForegroundColor White
Write-Host "flutter create my_app - Create new Flutter project" -ForegroundColor White
Write-Host "flutter run - Run Flutter app" -ForegroundColor White
Write-Host "flutter build - Build Flutter app" -ForegroundColor White