Skip to content

Commit f00d361

Browse files
committed
Improve Flutter SDK installation and detection
Refactored Flutter SDK installation logic to prompt users before installing if the SDK is missing or invalid, and added get_flutter_dir utility for consistent SDK path resolution. Enhanced batch file detection to check the expected install directory first, and standardized user prompts for SDK installation.
1 parent 0978de0 commit f00d361

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

sdk/python/packages/flet-cli/src/flet_cli/commands/flutter_base.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from flet.utils import cleanup_path, is_windows
1919
from flet.utils.platform_utils import get_bool_env_var
2020
from flet_cli.commands.base import BaseCommand
21+
from flet_cli.utils.flutter import get_flutter_dir, install_flutter
2122

2223
PYODIDE_ROOT_URL = "https://cdn.jsdelivr.net/pyodide/v0.27.7/full"
2324
DEFAULT_TEMPLATE_URL = "gh:flet-dev/flet-build-template"
@@ -118,6 +119,24 @@ def initialize_command(self):
118119
or not self.dart_exe
119120
or not self.flutter_version_valid()
120121
):
122+
if not self.assume_yes:
123+
console.log(
124+
"Flutter SDK not found or invalid version installed.",
125+
style=warning_style,
126+
)
127+
prompt = (
128+
"Flutter SDK "
129+
f"{MINIMAL_FLUTTER_VERSION} is required. It will be installed now. "
130+
"Proceed? [y/n] "
131+
)
132+
133+
if not self._prompt_input(prompt):
134+
self.skip_flutter_doctor = True
135+
self.cleanup(
136+
1,
137+
"Flutter SDK installation is required. "
138+
"Re-run with --yes to install automatically.",
139+
)
121140
self.install_flutter()
122141

123142
if self.verbose > 0:
@@ -164,7 +183,6 @@ def install_flutter(self):
164183
self.update_status(
165184
f"[bold blue]Installing Flutter {MINIMAL_FLUTTER_VERSION}..."
166185
)
167-
from flet_cli.utils.flutter import install_flutter
168186

169187
flutter_dir = install_flutter(
170188
str(MINIMAL_FLUTTER_VERSION), self.log_stdout, progress=self.progress
@@ -270,7 +288,7 @@ def _confirm_android_sdk_installation(self) -> bool:
270288

271289
prompt = (
272290
"\nAndroid SDK is required. If it's missing or incomplete, "
273-
"it will be installed now. Proceed? [y/N] "
291+
"it will be installed now. Proceed? [y/n] "
274292
)
275293

276294
if self._prompt_input(prompt):
@@ -286,6 +304,12 @@ def _prompt_input(self, prompt: str) -> bool:
286304
self.live.start()
287305

288306
def find_flutter_batch(self, exe_filename: str):
307+
install_dir = get_flutter_dir(str(MINIMAL_FLUTTER_VERSION))
308+
ext = ".bat" if is_windows() else ""
309+
batch_path = os.path.join(install_dir, "bin", f"{exe_filename}{ext}")
310+
if os.path.exists(batch_path):
311+
return batch_path
312+
289313
batch_path = shutil.which(exe_filename)
290314
if not batch_path:
291315
return None

sdk/python/packages/flet-cli/src/flet_cli/utils/flutter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
from pathlib import Path
55
from typing import Optional
66

7-
from flet_cli.utils.distros import download_with_progress, extract_with_progress
87
from rich.console import Console
98
from rich.progress import Progress
109

10+
from flet_cli.utils.distros import download_with_progress, extract_with_progress
11+
1112

1213
def get_flutter_url(version):
1314
"""Determines the Flutter archive URL based on the platform."""
@@ -28,9 +29,14 @@ def get_flutter_url(version):
2829
raise ValueError(f"Unsupported platform: {system}")
2930

3031

32+
def get_flutter_dir(version):
33+
home_dir = Path.home()
34+
return os.path.join(home_dir, "flutter", version)
35+
36+
3137
def install_flutter(version, log, progress: Optional[Progress] = None):
38+
install_dir = get_flutter_dir(version)
3239
home_dir = Path.home()
33-
install_dir = os.path.join(home_dir, "flutter", version)
3440

3541
if not os.path.exists(install_dir):
3642
url = get_flutter_url(version)

0 commit comments

Comments
 (0)