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
This commit is contained in:
parent
b83f762dd5
commit
5d8cc978b9
@ -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.
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user