@@ -20,7 +20,6 @@ import 'src/context_runner.dart';
2020import 'src/doctor.dart' ;
2121import 'src/globals.dart' as globals;
2222import 'src/reporting/crash_reporting.dart' ;
23- import 'src/reporting/first_run.dart' ;
2423import 'src/reporting/reporting.dart' ;
2524import 'src/runner/flutter_command.dart' ;
2625import 'src/runner/flutter_command_runner.dart' ;
@@ -115,7 +114,7 @@ Future<int> run(
115114 // Triggering [runZoned]'s error callback does not necessarily mean that
116115 // we stopped executing the body. See https://github.com/dart-lang/sdk/issues/42150.
117116 if (firstError == null ) {
118- return await _exit (0 , shutdownHooks: shutdownHooks);
117+ return await exitWithHooks (0 , shutdownHooks: shutdownHooks);
119118 }
120119
121120 // We already hit some error, so don't return success. The error path
@@ -151,22 +150,22 @@ Future<int> _handleToolError(
151150 globals.printError ('${error .message }\n ' );
152151 globals.printError ("Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and options." );
153152 // Argument error exit code.
154- return _exit (64 , shutdownHooks: shutdownHooks);
153+ return exitWithHooks (64 , shutdownHooks: shutdownHooks);
155154 } else if (error is ToolExit ) {
156155 if (error.message != null ) {
157156 globals.printError (error.message! );
158157 }
159158 if (verbose) {
160159 globals.printError ('\n $stackTrace \n ' );
161160 }
162- return _exit (error.exitCode ?? 1 , shutdownHooks: shutdownHooks);
161+ return exitWithHooks (error.exitCode ?? 1 , shutdownHooks: shutdownHooks);
163162 } else if (error is ProcessExit ) {
164163 // We've caught an exit code.
165164 if (error.immediate) {
166165 exit (error.exitCode);
167166 return error.exitCode;
168167 } else {
169- return _exit (error.exitCode, shutdownHooks: shutdownHooks);
168+ return exitWithHooks (error.exitCode, shutdownHooks: shutdownHooks);
170169 }
171170 } else {
172171 // We've crashed; emit a log report.
@@ -176,7 +175,7 @@ Future<int> _handleToolError(
176175 // Print the stack trace on the bots - don't write a crash report.
177176 globals.stdio.stderrWrite ('$error \n ' );
178177 globals.stdio.stderrWrite ('$stackTrace \n ' );
179- return _exit (1 , shutdownHooks: shutdownHooks);
178+ return exitWithHooks (1 , shutdownHooks: shutdownHooks);
180179 }
181180
182181 // Report to both [Usage] and [CrashReportSender].
@@ -217,7 +216,7 @@ Future<int> _handleToolError(
217216 final File file = await _createLocalCrashReport (details);
218217 await globals.crashReporter! .informUser (details, file);
219218
220- return _exit (1 , shutdownHooks: shutdownHooks);
219+ return exitWithHooks (1 , shutdownHooks: shutdownHooks);
221220 // This catch catches all exceptions to ensure the message below is printed.
222221 } catch (error, st) { // ignore: avoid_catches_without_on_clauses
223222 globals.stdio.stderrWrite (
@@ -283,76 +282,3 @@ Future<File> _createLocalCrashReport(CrashDetails details) async {
283282
284283 return crashFile;
285284}
286-
287- Future <int > _exit (int code, {required ShutdownHooks shutdownHooks}) async {
288- // Need to get the boolean returned from `messenger.shouldDisplayLicenseTerms()`
289- // before invoking the print welcome method because the print welcome method
290- // will set `messenger.shouldDisplayLicenseTerms()` to false
291- final FirstRunMessenger messenger =
292- FirstRunMessenger (persistentToolState: globals.persistentToolState! );
293- final bool legacyAnalyticsMessageShown =
294- messenger.shouldDisplayLicenseTerms ();
295-
296- // Prints the welcome message if needed for legacy analytics.
297- globals.flutterUsage.printWelcome ();
298-
299- // Ensure that the consent message has been displayed for unified analytics
300- if (globals.analytics.shouldShowMessage) {
301- globals.logger.printStatus (globals.analytics.getConsentMessage);
302- if (! globals.flutterUsage.enabled) {
303- globals.printStatus (
304- 'Please note that analytics reporting was already disabled, '
305- 'and will continue to be disabled.\n ' );
306- }
307-
308- // Because the legacy analytics may have also sent a message,
309- // the conditional below will print additional messaging informing
310- // users that the two consent messages they are receiving is not a
311- // bug
312- if (legacyAnalyticsMessageShown) {
313- globals.logger
314- .printStatus ('You have received two consent messages because '
315- 'the flutter tool is migrating to a new analytics system. '
316- 'Disabling analytics collection will disable both the legacy '
317- 'and new analytics collection systems. '
318- 'You can disable analytics reporting by running `flutter --disable-analytics`\n ' );
319- }
320-
321- // Invoking this will onboard the flutter tool onto
322- // the package on the developer's machine and will
323- // allow for events to be sent to Google Analytics
324- // on subsequent runs of the flutter tool (ie. no events
325- // will be sent on the first run to allow developers to
326- // opt out of collection)
327- globals.analytics.clientShowedMessage ();
328- }
329-
330- // Send any last analytics calls that are in progress without overly delaying
331- // the tool's exit (we wait a maximum of 250ms).
332- if (globals.flutterUsage.enabled) {
333- final Stopwatch stopwatch = Stopwatch ()..start ();
334- await globals.flutterUsage.ensureAnalyticsSent ();
335- globals.printTrace ('ensureAnalyticsSent: ${stopwatch .elapsedMilliseconds }ms' );
336- }
337-
338- // Run shutdown hooks before flushing logs
339- await shutdownHooks.runShutdownHooks (globals.logger);
340-
341- final Completer <void > completer = Completer <void >();
342-
343- // Give the task / timer queue one cycle through before we hard exit.
344- Timer .run (() {
345- try {
346- globals.printTrace ('exiting with code $code ' );
347- exit (code);
348- completer.complete ();
349- // This catches all exceptions because the error is propagated on the
350- // completer.
351- } catch (error, stackTrace) { // ignore: avoid_catches_without_on_clauses
352- completer.completeError (error, stackTrace);
353- }
354- });
355-
356- await completer.future;
357- return code;
358- }
0 commit comments