@@ -349,7 +349,6 @@ class _DefaultPub implements Pub {
349349 context: context,
350350 directory: directory,
351351 failureMessage: 'pub $command failed' ,
352- retry: ! offline,
353352 flutterRootOverride: flutterRootOverride,
354353 printProgress: printProgress
355354 );
@@ -379,59 +378,83 @@ class _DefaultPub implements Pub {
379378 /// Uses [ProcessStartMode.normal] and [Pub._stdio] if [Pub.test] constructor
380379 /// was used.
381380 ///
382- /// Prints the stdout and stderr of the whole run.
381+ /// Prints the stdout and stderr of the whole run, unless silenced using
382+ /// [printProgress] .
383383 ///
384384 /// Sends an analytics event.
385385 Future <void > _runWithStdioInherited (
386386 List <String > arguments, {
387387 required String command,
388388 required bool printProgress,
389389 required PubContext context,
390- required bool retry,
391390 required String directory,
392391 String failureMessage = 'pub failed' ,
393392 String ? flutterRootOverride,
394393 }) async {
395394 int exitCode;
395+ if (printProgress) {
396+ _logger.printStatus ('Running "flutter pub $command " in ${_fileSystem .path .basename (directory )}...' );
397+ }
396398
397- _logger.printStatus ('Running "flutter pub $command " in ${_fileSystem .path .basename (directory )}...' );
398399 final List <String > pubCommand = _pubCommand (arguments);
399400 final Map <String , String > pubEnvironment = await _createPubEnvironment (context, flutterRootOverride);
400- try {
401- final io.Process process;
402- final io.Stdio ? stdio = _stdio;
403-
404- if (stdio != null ) {
405- // Omit mode parameter and direct pub output to [Pub._stdio] for tests.
406- process = await _processUtils.start (
407- pubCommand,
408- workingDirectory: _fileSystem.path.current,
409- environment: pubEnvironment,
410- );
411401
412- final StreamSubscription <List <int >> stdoutSubscription =
413- process.stdout.listen (stdio.stdout.add);
414- final StreamSubscription <List <int >> stderrSubscription =
415- process.stderr.listen (stdio.stderr.add);
416-
417- await Future .wait <void >(< Future <void >> [
418- stdoutSubscription.asFuture <void >(),
419- stderrSubscription.asFuture <void >(),
420- ]);
421-
422- unawaited (stdoutSubscription.cancel ());
423- unawaited (stderrSubscription.cancel ());
402+ try {
403+ if (printProgress) {
404+ final io.Stdio ? stdio = _stdio;
405+ if (stdio == null ) {
406+ // Let pub inherit stdio and output directly to the tool's stdout and
407+ // stderr handles.
408+ final io.Process process = await _processUtils.start (
409+ pubCommand,
410+ workingDirectory: _fileSystem.path.current,
411+ environment: pubEnvironment,
412+ mode: ProcessStartMode .inheritStdio,
413+ );
414+
415+ exitCode = await process.exitCode;
416+ } else {
417+ // Omit [mode] parameter to send output to [process.stdout] and
418+ // [process.stderr].
419+ final io.Process process = await _processUtils.start (
420+ pubCommand,
421+ workingDirectory: _fileSystem.path.current,
422+ environment: pubEnvironment,
423+ );
424+
425+ // Direct pub output to [Pub._stdio] for tests.
426+ final StreamSubscription <List <int >> stdoutSubscription =
427+ process.stdout.listen (stdio.stdout.add);
428+ final StreamSubscription <List <int >> stderrSubscription =
429+ process.stderr.listen (stdio.stderr.add);
430+
431+ await Future .wait <void >(< Future <void >> [
432+ stdoutSubscription.asFuture <void >(),
433+ stderrSubscription.asFuture <void >(),
434+ ]);
435+
436+ unawaited (stdoutSubscription.cancel ());
437+ unawaited (stderrSubscription.cancel ());
438+
439+ exitCode = await process.exitCode;
440+ }
424441 } else {
425- // Let pub inherit stdio for normal operation.
426- process = await _processUtils.start (
442+ // Do not try to use [ProcessUtils.start] here, because it requires you
443+ // to read all data out of the stdout and stderr streams. If you don't
444+ // read the streams, it may appear to work fine on your platform but
445+ // will block the tool's process on Windows.
446+ // See https://api.dart.dev/stable/dart-io/Process/start.html
447+ //
448+ // [ProcessUtils.run] will send the output to [result.stdout] and
449+ // [result.stderr], which we will ignore.
450+ final RunResult result = await _processUtils.run (
427451 pubCommand,
428452 workingDirectory: _fileSystem.path.current,
429453 environment: pubEnvironment,
430- mode: ProcessStartMode .inheritStdio,
431454 );
432- }
433455
434- exitCode = await process.exitCode;
456+ exitCode = result.exitCode;
457+ }
435458 // The exception is rethrown, so don't catch only Exceptions.
436459 } catch (exception) { // ignore: avoid_catches_without_on_clauses
437460 if (exception is io.ProcessException ) {
0 commit comments