33// found in the LICENSE file.
44
55import 'package:meta/meta.dart' ;
6- import 'package:process/process.dart' ;
76
87import '../base/common.dart' ;
98import '../base/file_system.dart' ;
@@ -12,8 +11,8 @@ import '../base/logger.dart';
1211import '../base/process.dart' ;
1312import '../base/terminal.dart' ;
1413import '../cache.dart' ;
14+ import '../context/tool_context.dart' ;
1515import '../git.dart' ;
16- import '../globals.dart' as globals;
1716import '../persistent_tool_state.dart' ;
1817import '../runner/flutter_command.dart' ;
1918import '../version.dart' ;
@@ -41,21 +40,15 @@ String downgradePositionalArgumentErrorMessage(List<String> args) {
4140/// Additionally, if they had switched channels to stable before trying to downgrade,
4241/// the command would fail since there was no previously recorded stable version.
4342class DowngradeCommand extends FlutterCommand {
44- DowngradeCommand ({
45- bool verboseHelp = false ,
46- PersistentToolState ? persistentToolState,
47- required Logger logger,
48- FlutterVersion ? flutterVersion,
49- Terminal ? terminal,
50- Stdio ? stdio,
51- FileSystem ? fileSystem,
52- }) : _terminal = terminal,
53- _flutterVersion = flutterVersion,
54- _persistentToolState = persistentToolState,
55- _stdio = stdio,
56- _logger = logger,
57- _fileSystem = fileSystem,
58- _git = globals.git {
43+ DowngradeCommand ({required ToolContext toolContext, bool verboseHelp = false })
44+ : _terminal = toolContext.terminal,
45+ _flutterVersion = toolContext.flutterVersion,
46+ _persistentToolState = toolContext.persistentToolState,
47+ _stdio = toolContext.stdio,
48+ _logger = toolContext.logger,
49+ _fileSystem = toolContext.fs,
50+ _git = toolContext.git,
51+ super (toolContext: toolContext, verboseHelp: verboseHelp) {
5952 argParser.addOption (
6053 'working-directory' ,
6154 hide: ! verboseHelp,
@@ -73,14 +66,13 @@ class DowngradeCommand extends FlutterCommand {
7366 );
7467 }
7568
76- Terminal ? _terminal;
77- FlutterVersion ? _flutterVersion;
78- PersistentToolState ? _persistentToolState;
79- ProcessManager ? _processManager;
69+ final Terminal _terminal;
70+ FlutterVersion _flutterVersion;
71+ final PersistentToolState _persistentToolState;
8072 final Logger _logger;
8173 final Git _git;
82- Stdio ? _stdio;
83- FileSystem ? _fileSystem;
74+ final Stdio _stdio;
75+ final FileSystem _fileSystem;
8476
8577 @override
8678 String get description => 'Downgrade Flutter to the last active version for the current channel.' ;
@@ -100,29 +92,22 @@ class DowngradeCommand extends FlutterCommand {
10092 // Commands do not necessarily have access to the correct zone injected
10193 // values when being created. Fields must be lazily instantiated in runCommand,
10294 // at least until the zone injection is refactored.
103- _terminal ?? = globals.terminal;
104- _flutterVersion ?? = globals.flutterVersion;
105- _persistentToolState ?? = globals.persistentToolState;
106- _processManager ?? = globals.processManager;
107- _stdio ?? = globals.stdio;
108- _fileSystem ?? = globals.fs;
10995 String workingDirectory = Cache .flutterRoot! ;
11096 if (argResults! .wasParsed ('working-directory' )) {
11197 workingDirectory = stringArg ('working-directory' )! ;
112- _flutterVersion = FlutterVersion (fs: _fileSystem! , flutterRoot: workingDirectory, git: _git);
98+ _flutterVersion = FlutterVersion (fs: _fileSystem, flutterRoot: workingDirectory, git: _git);
11399 }
114100
115- final String currentChannel = _flutterVersion! .channel;
101+ final String currentChannel = _flutterVersion.channel;
116102 final Channel ? channel = getChannelForName (currentChannel);
117103 if (channel == null ) {
118104 throwToolExit (
119105 'Flutter is not currently on a known channel. '
120106 'Use "flutter channel" to switch to an official channel. ' ,
121107 );
122108 }
123- final PersistentToolState persistentToolState = _persistentToolState! ;
124- final String ? lastFlutterVersion = persistentToolState.lastActiveVersion (channel);
125- final String ? currentFlutterVersion = _flutterVersion? .frameworkRevision;
109+ final String ? lastFlutterVersion = _persistentToolState.lastActiveVersion (channel);
110+ final String currentFlutterVersion = _flutterVersion.frameworkRevision;
126111 if (lastFlutterVersion == null || currentFlutterVersion == lastFlutterVersion) {
127112 final String trailing = await _createErrorMessage (workingDirectory, channel);
128113 throwToolExit (
@@ -149,11 +134,9 @@ class DowngradeCommand extends FlutterCommand {
149134 final String humanReadableVersion = parseResult.stdout;
150135
151136 // If there is a terminal attached, prompt the user to confirm the downgrade.
152- final Stdio stdio = _stdio! ;
153- final Terminal terminal = _terminal! ;
154- if (stdio.hasTerminal && boolArg ('prompt' )) {
155- terminal.usesTerminalUi = true ;
156- final String result = await terminal.promptForCharInput (
137+ if (_stdio.hasTerminal && boolArg ('prompt' )) {
138+ _terminal.usesTerminalUi = true ;
139+ final String result = await _terminal.promptForCharInput (
157140 const < String > ['y' , 'n' ],
158141 prompt: 'Downgrade flutter to version $humanReadableVersion ?' ,
159142 logger: _logger,
@@ -208,7 +191,7 @@ class DowngradeCommand extends FlutterCommand {
208191 if (channel == currentChannel) {
209192 continue ;
210193 }
211- final String ? sha = _persistentToolState? .lastActiveVersion (channel);
194+ final String ? sha = _persistentToolState.lastActiveVersion (channel);
212195 if (sha == null ) {
213196 continue ;
214197 }
0 commit comments