Skip to content

Commit f4c2121

Browse files
authored
[UA] Bump dart to 3.10 (#2324)
Reformat and use null check collection elements.
1 parent dc3c224 commit f4c2121

27 files changed

Lines changed: 2323 additions & 1798 deletions

pkgs/unified_analytics/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 8.0.12-wip
2+
- Require Dart 3.10
3+
14
## 8.0.11
25
- Added `Event.flutterTrackAndroidDependencies` to track android dependencies.
36
- Deprecated `Event.flutterWasmDryRun` in favor of `Event.flutterWasmDryRunPackage`.

pkgs/unified_analytics/example/serving_surveys.dart

Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -47,47 +47,48 @@ void main() async {
4747

4848
// ignore: invalid_use_of_visible_for_testing_member
4949
analytics = Analytics.fake(
50-
tool: DashTool.flutterTool,
51-
homeDirectory: home,
52-
dartVersion: 'dartVersion',
53-
fs: fs,
54-
platform: DevicePlatform.macos,
55-
surveyHandler: FakeSurveyHandler.fromList(
56-
dismissedSurveyFile: home
57-
.childDirectory(kDartToolDirectoryName)
58-
.childFile(kDismissedSurveyFileName),
59-
initializedSurveys: [
60-
Survey(
61-
uniqueId: 'uniqueId',
62-
startDate: DateTime(2023, 1, 1),
63-
endDate: DateTime(2023, 5, 31),
64-
description: 'description',
65-
snoozeForMinutes: 10,
66-
samplingRate: 1.0,
67-
excludeDashToolList: [],
68-
conditionList: [],
69-
buttonList: [
70-
SurveyButton(
71-
buttonText: 'View Survey',
72-
action: 'accept',
73-
promptRemainsVisible: false,
74-
url: 'http://example.com',
75-
),
76-
SurveyButton(
77-
buttonText: 'More Info',
78-
action: 'snooze',
79-
promptRemainsVisible: true,
80-
url: 'http://example2.com',
81-
),
82-
SurveyButton(
83-
buttonText: 'Dismiss Survey',
84-
action: 'dismiss',
85-
promptRemainsVisible: false,
86-
)
87-
],
88-
),
89-
],
90-
));
50+
tool: DashTool.flutterTool,
51+
homeDirectory: home,
52+
dartVersion: 'dartVersion',
53+
fs: fs,
54+
platform: DevicePlatform.macos,
55+
surveyHandler: FakeSurveyHandler.fromList(
56+
dismissedSurveyFile: home
57+
.childDirectory(kDartToolDirectoryName)
58+
.childFile(kDismissedSurveyFileName),
59+
initializedSurveys: [
60+
Survey(
61+
uniqueId: 'uniqueId',
62+
startDate: DateTime(2023, 1, 1),
63+
endDate: DateTime(2023, 5, 31),
64+
description: 'description',
65+
snoozeForMinutes: 10,
66+
samplingRate: 1.0,
67+
excludeDashToolList: [],
68+
conditionList: [],
69+
buttonList: [
70+
SurveyButton(
71+
buttonText: 'View Survey',
72+
action: 'accept',
73+
promptRemainsVisible: false,
74+
url: 'http://example.com',
75+
),
76+
SurveyButton(
77+
buttonText: 'More Info',
78+
action: 'snooze',
79+
promptRemainsVisible: true,
80+
url: 'http://example2.com',
81+
),
82+
SurveyButton(
83+
buttonText: 'Dismiss Survey',
84+
action: 'dismiss',
85+
promptRemainsVisible: false,
86+
),
87+
],
88+
),
89+
],
90+
),
91+
);
9192
});
9293

9394
// Each client of this package will be able to fetch all of
@@ -116,8 +117,10 @@ void main() async {
116117
final persistedSurveyFile = home
117118
.childDirectory(kDartToolDirectoryName)
118119
.childFile(kDismissedSurveyFileName);
119-
print('The contents of the json file '
120-
'after invoking `analytics.surveyShown(survey);`');
120+
print(
121+
'The contents of the json file '
122+
'after invoking `analytics.surveyShown(survey);`',
123+
);
121124
print('${persistedSurveyFile.readAsStringSync()}\n');
122125

123126
// Change the index below to decide which button to simulate pressing
@@ -131,9 +134,11 @@ void main() async {
131134
// Get the survey button by index that will need to be passed along with
132135
// the survey to simulate an interaction with the survey
133136
final selectedSurveyButton = survey.buttonList[selectedButtonIndex];
134-
print('The simulated button pressed was: '
135-
'"${selectedSurveyButton.buttonText}" '
136-
'(action = ${selectedSurveyButton.action})\n');
137+
print(
138+
'The simulated button pressed was: '
139+
'"${selectedSurveyButton.buttonText}" '
140+
'(action = ${selectedSurveyButton.action})\n',
141+
);
137142

138143
// The below method will handle whatever action the button
139144
analytics.surveyInteracted(
@@ -143,20 +148,26 @@ void main() async {
143148

144149
// Conditional to check if there is a URl to route to
145150
if (selectedSurveyButton.url != null) {
146-
print('***This button also has a survey URL link '
147-
'to route to at "${selectedSurveyButton.url}"***\n');
151+
print(
152+
'***This button also has a survey URL link '
153+
'to route to at "${selectedSurveyButton.url}"***\n',
154+
);
148155
}
149156

150157
// Conditional to check what simulating a popup to stay up
151158
if (selectedSurveyButton.promptRemainsVisible) {
152-
print('***This button has its promptRemainsVisible field set to `true` '
153-
'so this simulates what seeing a pop up again would look like***\n');
159+
print(
160+
'***This button has its promptRemainsVisible field set to `true` '
161+
'so this simulates what seeing a pop up again would look like***\n',
162+
);
154163
}
155164

156-
print('The contents of the json file '
157-
'after invoking '
158-
'`analytics.surveyInteracted(survey: survey, '
159-
'surveyButton: selectedSurveyButton);`');
165+
print(
166+
'The contents of the json file '
167+
'after invoking '
168+
'`analytics.surveyInteracted(survey: survey, '
169+
'surveyButton: selectedSurveyButton);`',
170+
);
160171
print('${persistedSurveyFile.readAsStringSync()}\n');
161172

162173
// Demonstrating that the survey doesn't get returned again

pkgs/unified_analytics/example/unified_analytics_example.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ void main() async {
4444
analytics.clientShowedMessage();
4545
}
4646

47-
print('Current user ${analytics.clientId} '
48-
'is opted in: ${analytics.telemetryEnabled}');
47+
print(
48+
'Current user ${analytics.clientId} '
49+
'is opted in: ${analytics.telemetryEnabled}',
50+
);
4951

5052
// Example of long running process
5153
await Future<void>.delayed(const Duration(milliseconds: 100));

pkgs/unified_analytics/lib/src/analytics.dart

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ abstract class Analytics {
126126
// Ensure that the home directory has permissions enabled to write
127127
final homeDirectory = getHomeDirectory(fs);
128128
if (homeDirectory == null) {
129-
throw Exception('Unable to determine the home directory, '
130-
'ensure it is available in the environment');
129+
throw Exception(
130+
'Unable to determine the home directory, '
131+
'ensure it is available in the environment',
132+
);
131133
}
132134
if (!checkDirectoryForWritePermissions(homeDirectory)) {
133135
throw Exception('Permissions error on the home directory!');
@@ -313,7 +315,8 @@ abstract class Analytics {
313315
dartVersion: dartVersion,
314316
platform: platform,
315317
fs: fs,
316-
surveyHandler: surveyHandler ??
318+
surveyHandler:
319+
surveyHandler ??
317320
FakeSurveyHandler.fromList(
318321
dismissedSurveyFile: homeDirectory
319322
.childDirectory(kDartToolDirectoryName)
@@ -386,40 +389,42 @@ class AnalyticsImpl implements Analytics {
386389
required SurveyHandler surveyHandler,
387390
required bool enableAsserts,
388391
required bool firstRun,
389-
}) : _gaClient = gaClient,
390-
_surveyHandler = surveyHandler,
391-
_enableAsserts = enableAsserts,
392-
_clientIdFile = homeDirectory
393-
.childDirectory(kDartToolDirectoryName)
394-
.childFile(kClientIdFileName),
395-
_userProperty = UserProperty(
396-
sessionFile: homeDirectory
397-
.childDirectory(kDartToolDirectoryName)
398-
.childFile(kSessionFileName),
399-
flutterChannel: flutterChannel,
400-
host: platform.label,
401-
flutterVersion: flutterVersion,
402-
dartVersion: dartVersion,
403-
tool: tool.label,
404-
// We truncate this to a maximum of 36 characters since this can
405-
// a very long string for some operating systems
406-
hostOsVersion:
407-
truncateStringToLength(io.Platform.operatingSystemVersion, 36),
408-
locale: io.Platform.localeName,
409-
clientIde: clientIde,
410-
),
411-
_enabledFeatures = enabledFeatures,
412-
_configHandler = ConfigHandler(
413-
homeDirectory: homeDirectory,
414-
configFile: homeDirectory
415-
.childDirectory(kDartToolDirectoryName)
416-
.childFile(kConfigFileName),
417-
),
418-
_logHandler = LogHandler(
419-
logFile: homeDirectory
420-
.childDirectory(kDartToolDirectoryName)
421-
.childFile(kLogFileName),
422-
) {
392+
}) : _gaClient = gaClient,
393+
_surveyHandler = surveyHandler,
394+
_enableAsserts = enableAsserts,
395+
_clientIdFile = homeDirectory
396+
.childDirectory(kDartToolDirectoryName)
397+
.childFile(kClientIdFileName),
398+
_userProperty = UserProperty(
399+
sessionFile: homeDirectory
400+
.childDirectory(kDartToolDirectoryName)
401+
.childFile(kSessionFileName),
402+
flutterChannel: flutterChannel,
403+
host: platform.label,
404+
flutterVersion: flutterVersion,
405+
dartVersion: dartVersion,
406+
tool: tool.label,
407+
// We truncate this to a maximum of 36 characters since this can
408+
// a very long string for some operating systems
409+
hostOsVersion: truncateStringToLength(
410+
io.Platform.operatingSystemVersion,
411+
36,
412+
),
413+
locale: io.Platform.localeName,
414+
clientIde: clientIde,
415+
),
416+
_enabledFeatures = enabledFeatures,
417+
_configHandler = ConfigHandler(
418+
homeDirectory: homeDirectory,
419+
configFile: homeDirectory
420+
.childDirectory(kDartToolDirectoryName)
421+
.childFile(kConfigFileName),
422+
),
423+
_logHandler = LogHandler(
424+
logFile: homeDirectory
425+
.childDirectory(kDartToolDirectoryName)
426+
.childFile(kLogFileName),
427+
) {
423428
// This initializer class will let the instance know
424429
// if it was the first run; if it is, nothing will be sent
425430
// on the first run
@@ -464,8 +469,8 @@ class AnalyticsImpl implements Analytics {
464469
// The command to swap in the consent message
465470
final commandString =
466471
tool == DashTool.flutterTool || tool == DashTool.devtools
467-
? 'flutter'
468-
: 'dart';
472+
? 'flutter'
473+
: 'dart';
469474

470475
return kToolsMessage
471476
.replaceAll('{{ toolDescription }}', tool.description)
@@ -529,10 +534,9 @@ class AnalyticsImpl implements Analytics {
529534
// Collect any errors encountered and send
530535
_sendPendingErrorEvents();
531536

532-
await Future.wait(_futures).timeout(
533-
Duration(milliseconds: delayDuration),
534-
onTimeout: () => [],
535-
);
537+
await Future.wait(
538+
_futures,
539+
).timeout(Duration(milliseconds: delayDuration), onTimeout: () => []);
536540
_gaClient.close();
537541
}
538542

@@ -571,8 +575,9 @@ class AnalyticsImpl implements Analytics {
571575
for (final condition in survey.conditionList) {
572576
// Retrieve the value from the [LogFileStats] with
573577
// the label provided in the condtion
574-
final logFileStatsValue =
575-
logFileStats.getValueByString(condition.field);
578+
final logFileStatsValue = logFileStats.getValueByString(
579+
condition.field,
580+
);
576581

577582
if (logFileStatsValue == null) continue;
578583

@@ -631,8 +636,9 @@ class AnalyticsImpl implements Analytics {
631636
_configHandler.setTelemetry(reportingBool);
632637

633638
// Creation of the [Event] for opting out
634-
final collectionEvent =
635-
Event.analyticsCollectionEnabled(status: reportingBool);
639+
final collectionEvent = Event.analyticsCollectionEnabled(
640+
status: reportingBool,
641+
);
636642

637643
// The body of the request that will be sent to GA4
638644
final Map<String, Object?> body;
@@ -681,7 +687,9 @@ class AnalyticsImpl implements Analytics {
681687

682688
// Pass to the google analytics client to send with a
683689
// timeout incase http clients hang
684-
return _gaClient.sendData(body).timeout(
690+
return _gaClient
691+
.sendData(body)
692+
.timeout(
685693
const Duration(milliseconds: kDelayDuration),
686694
onTimeout: () => Response('', 200),
687695
);
@@ -698,10 +706,12 @@ class AnalyticsImpl implements Analytics {
698706
// Any action, except for 'snooze' will permanently dismiss a given survey
699707
final permanentlyDismissed = surveyButton.action == 'snooze' ? false : true;
700708
_surveyHandler.dismiss(survey, permanentlyDismissed);
701-
send(Event.surveyAction(
702-
surveyId: survey.uniqueId,
703-
status: surveyButton.action,
704-
));
709+
send(
710+
Event.surveyAction(
711+
surveyId: survey.uniqueId,
712+
status: surveyButton.action,
713+
),
714+
);
705715
}
706716

707717
@override
@@ -721,9 +731,11 @@ class AnalyticsImpl implements Analytics {
721731
// Collect any errors encountered and send
722732
final errorEvents = {..._userProperty.errorSet, ..._logHandler.errorSet};
723733
errorEvents
724-
.where((event) =>
725-
event.eventName == DashEvent.analyticsException &&
726-
!_sentErrorEvents.contains(event))
734+
.where(
735+
(event) =>
736+
event.eventName == DashEvent.analyticsException &&
737+
!_sentErrorEvents.contains(event),
738+
)
727739
.forEach(send);
728740

729741
// Ensure the same event doesn't get sent again

pkgs/unified_analytics/lib/src/asserts.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ void checkBody(Map<String, Object?> body) {
145145
// GA4 Limitation:
146146
// User property names must be 24 characters or fewer
147147
if (key.length > 24) {
148-
throw AnalyticsException('Limit user property names to 24 chars or less\n'
149-
'The user property key: "$key" is too long');
148+
throw AnalyticsException(
149+
'Limit user property names to 24 chars or less\n'
150+
'The user property key: "$key" is too long',
151+
);
150152
}
151153

152154
// GA4 Limitation:

0 commit comments

Comments
 (0)