Unverified Commit 5d8cc978 authored by Elias Yishak's avatar Elias Yishak Committed by GitHub

Refactor `Analytics` global getter to point to context only (#129196)

Refactor the globals getter for `Analytics` to be in the context instead of having a default fallback. The current state of the tool creates a new instance every time `globals.analytics` was called

Addresses issue:
- https://github.com/flutter/flutter/issues/128535
parent b83f762d
......@@ -7,6 +7,7 @@
import 'dart:async';
import 'package:process/process.dart';
import 'package:unified_analytics/unified_analytics.dart';
import 'android/android_builder.dart';
import 'android/android_sdk.dart';
......@@ -87,6 +88,12 @@ Future<T> runInContext<T>(
body: runnerWrapper,
overrides: overrides,
fallbacks: <Type, Generator>{
Analytics: () => Analytics(
tool: DashTool.flutterTool,
flutterChannel: globals.flutterVersion.channel,
flutterVersion: globals.flutterVersion.frameworkVersion,
dartVersion: globals.flutterVersion.dartSdkVersion,
),
AndroidBuilder: () => AndroidGradleBuilder(
java: globals.java,
logger: globals.logger,
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:intl/date_symbol_data_local.dart';
import 'package:process/process.dart';
import 'package:unified_analytics/unified_analytics.dart';
......@@ -91,19 +90,7 @@ Future<bool> get isRunningOnBot => botDetector.isRunningOnBot;
// Analytics instance for package:unified_analytics for telemetry
// reporting for all Flutter and Dart related tooling
Analytics get analytics => context.get<Analytics>() ?? getDefaultAnalytics();
Analytics getDefaultAnalytics() {
initializeDateFormatting();
final Analytics defaultAnalytics = Analytics(
tool: DashTool.flutterTool,
flutterChannel: flutterVersion.channel,
flutterVersion: flutterVersion.frameworkVersion,
dartVersion: flutterVersion.dartSdkVersion,
);
return defaultAnalytics;
}
Analytics get analytics => context.get<Analytics>()!;
/// Currently active implementation of the file system.
///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment