1010from rich .console import Console , Group
1111from rich .panel import Panel
1212from rich .progress import Progress
13+ from rich .prompt import Confirm
1314from rich .style import Style
1415from rich .theme import Theme
1516
@@ -64,6 +65,8 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:
6465 "android" : "Android" ,
6566 None : "iOS/Android" ,
6667 }
68+ self .assume_yes = False
69+ self ._android_install_confirmed = False
6770
6871 def add_arguments (self , parser : argparse .ArgumentParser ) -> None :
6972 parser .add_argument (
@@ -72,6 +75,14 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
7275 default = False ,
7376 help = "Disable rich output and prefer plain text. Useful on Windows builds" ,
7477 )
78+ parser .add_argument (
79+ "--yes" ,
80+ dest = "assume_yes" ,
81+ action = "store_true" ,
82+ default = False ,
83+ help = "Answer yes to all prompts (install dependencies "
84+ "without confirmation)." ,
85+ )
7586 parser .add_argument (
7687 "--skip-flutter-doctor" ,
7788 action = "store_true" ,
@@ -83,6 +94,7 @@ def handle(self, options: argparse.Namespace) -> None:
8394 self .options = options
8495 self .no_rich_output = self .no_rich_output or self .options .no_rich_output
8596 self .verbose = self .options .verbose
97+ self .assume_yes = getattr (self .options , "assume_yes" , False )
8698
8799 def initialize_command (self ):
88100 assert self .options
@@ -113,6 +125,13 @@ def initialize_command(self):
113125 console .log ("Dart executable:" , self .dart_exe , style = verbose2_style )
114126
115127 if self .require_android_sdk :
128+ if not self ._confirm_android_sdk_installation ():
129+ self .skip_flutter_doctor = True
130+ self .cleanup (
131+ 1 ,
132+ "Android SDK installation is required. "
133+ "Re-run with --yes to install automatically." ,
134+ )
116135 self .install_jdk ()
117136 self .install_android_sdk ()
118137
@@ -237,6 +256,35 @@ def install_android_sdk(self):
237256 if self .verbose > 0 :
238257 console .log (f"Android SDK installed { self .emojis ['checkmark' ]} " )
239258
259+ def _confirm_android_sdk_installation (self ) -> bool :
260+ from flet_cli .utils .android_sdk import AndroidSDK
261+
262+ if AndroidSDK .has_minimal_packages_installed ():
263+ self ._android_install_confirmed = True
264+ return True
265+ if self ._android_install_confirmed :
266+ return True
267+ if self .assume_yes :
268+ self ._android_install_confirmed = True
269+ return True
270+
271+ prompt = (
272+ "\n Android SDK is required. If it's missing or incomplete, "
273+ "it will be installed now. Proceed? [y/N] "
274+ )
275+
276+ if self ._prompt_input (prompt ):
277+ self ._android_install_confirmed = True
278+ return True
279+ return False
280+
281+ def _prompt_input (self , prompt : str ) -> bool :
282+ self .live .stop ()
283+ try :
284+ return Confirm .ask (prompt , default = True )
285+ finally :
286+ self .live .start ()
287+
240288 def find_flutter_batch (self , exe_filename : str ):
241289 batch_path = shutil .which (exe_filename )
242290 if not batch_path :
0 commit comments