Skip to content

Commit bc6c9f0

Browse files
Clean up on dart docs across all dart files under lib (#142)
* Clean up across all dart files under lib * Fix format * Apply suggestions from code review Co-authored-by: Christopher Fujino <[email protected]> --------- Co-authored-by: Christopher Fujino <[email protected]>
1 parent f14bf2e commit bc6c9f0

File tree

13 files changed

+257
-226
lines changed

13 files changed

+257
-226
lines changed

pkgs/unified_analytics/lib/src/analytics.dart

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ import 'utils.dart';
2727

2828
abstract class Analytics {
2929
/// The default factory constructor that will return an implementation
30-
/// of the [Analytics] abstract class using the [LocalFileSystem]
30+
/// of the [Analytics] abstract class using the [LocalFileSystem].
3131
///
3232
/// If [enableAsserts] is set to `true`, then asserts for GA4 limitations
33-
/// will be enabled
33+
/// will be enabled.
34+
///
35+
/// [flutterChannel] and [flutterVersion] are nullable in case the client
36+
/// using this package is unable to resolve those values.
3437
factory Analytics({
3538
required DashTool tool,
3639
required String dartVersion,
@@ -83,10 +86,13 @@ abstract class Analytics {
8386

8487
/// Factory constructor to return the [AnalyticsImpl] class with
8588
/// Google Analytics credentials that point to a test instance and
86-
/// not the production instance where live data will be sent
89+
/// not the production instance where live data will be sent.
8790
///
8891
/// By default, [enableAsserts] is set to `true` to check against
89-
/// GA4 limitations
92+
/// GA4 limitations.
93+
///
94+
/// [flutterChannel] and [flutterVersion] are nullable in case the client
95+
/// using this package is unable to resolve those values.
9096
factory Analytics.development({
9197
required DashTool tool,
9298
required String dartVersion,
@@ -142,22 +148,22 @@ abstract class Analytics {
142148
}
143149

144150
/// Factory constructor to return the [AnalyticsImpl] class with a
145-
/// [MemoryFileSystem] to use for testing
151+
/// [MemoryFileSystem] to use for testing.
146152
@visibleForTesting
147153
factory Analytics.test({
148154
required DashTool tool,
149155
required Directory homeDirectory,
150156
required String measurementId,
151157
required String apiSecret,
152-
String? flutterChannel,
153-
String? flutterVersion,
154158
required String dartVersion,
155-
int toolsMessageVersion = kToolsMessageVersion,
156-
String toolsMessage = kToolsMessage,
157159
required FileSystem fs,
158160
required DevicePlatform platform,
161+
String? flutterChannel,
162+
String? flutterVersion,
159163
SurveyHandler? surveyHandler,
160164
GAClient? gaClient,
165+
int toolsMessageVersion = kToolsMessageVersion,
166+
String toolsMessage = kToolsMessage,
161167
}) =>
162168
AnalyticsImpl(
163169
tool: tool,
@@ -179,57 +185,57 @@ abstract class Analytics {
179185
);
180186

181187
/// Retrieves the consent message to prompt users with on first
182-
/// run or when the message has been updated
188+
/// run or when the message has been updated.
183189
String get getConsentMessage;
184190

185-
/// Returns true if it is OK to send an analytics message. Do not cache,
191+
/// Returns true if it is OK to send an analytics message. Do not cache,
186192
/// as this depends on factors that can change, such as the configuration
187193
/// file contents.
188194
bool get okToSend;
189195

190196
/// Returns a map object with all of the tools that have been parsed
191-
/// out of the configuration file
197+
/// out of the configuration file.
192198
Map<String, ToolInfo> get parsedTools;
193199

194-
/// Boolean that lets the client know if they should display the message
200+
/// Boolean that lets the client know if they should display the message.
195201
bool get shouldShowMessage;
196202

197-
/// Boolean indicating whether or not telemetry is enabled
203+
/// Boolean indicating whether or not telemetry is enabled.
198204
bool get telemetryEnabled;
199205

200206
/// Returns a map representation of the [UserProperty] for the [Analytics]
201207
/// instance.
202208
///
203-
/// This is what will get sent to Google Analytics with every request
209+
/// This is what will get sent to Google Analytics with every request.
204210
Map<String, Map<String, Object?>> get userPropertyMap;
205211

206212
/// Method to be invoked by the client using this package to confirm
207213
/// that the client has shown the message and that it can be added to
208-
/// the config file and start sending events the next time it starts up
214+
/// the config file and start sending events the next time it starts up.
209215
void clientShowedMessage();
210216

211-
/// Call this method when the tool using this package is closed
217+
/// Call this method when the tool using this package is closed.
212218
///
213219
/// Prevents the tool from hanging when if there are still requests
214-
/// that need to be sent off
220+
/// that need to be sent off.
215221
void close();
216222

217-
/// Method to fetch surveys from the specified endpoint [kContextualSurveyUrl]
223+
/// Method to fetch surveys from the endpoint [kContextualSurveyUrl].
218224
///
219225
/// Any survey that is returned by this method has already passed
220-
/// the survey conditions specified in the remote survey metadata file
226+
/// the survey conditions specified in the remote survey metadata file.
221227
///
222228
/// If the method returns an empty list, then there are no surveys to be
223-
/// shared with the user
229+
/// shared with the user.
224230
Future<List<Survey>> fetchAvailableSurveys();
225231

226-
/// Query the persisted event data stored on the user's machine
232+
/// Query the persisted event data stored on the user's machine.
227233
///
228-
/// Returns null if there are no persisted logs
234+
/// Returns null if there are no persisted logs.
229235
LogFileStats? logFileStats();
230236

231237
/// Send preconfigured events using specific named constructors
232-
/// on the [Event] class
238+
/// on the [Event] class.
233239
///
234240
/// Example
235241
/// ```dart
@@ -238,33 +244,37 @@ abstract class Analytics {
238244
Future<Response>? send(Event event);
239245

240246
/// Pass a boolean to either enable or disable telemetry and make
241-
/// the necessary changes in the persisted configuration file
247+
/// the necessary changes in the persisted configuration file.
242248
///
243249
/// Setting the telemetry status will also send an event to GA
244-
/// indicating the latest status of the telemetry from [reportingBool]
250+
/// indicating the latest status of the telemetry from [reportingBool].
245251
Future<void> setTelemetry(bool reportingBool);
246252

247253
/// Calling this will result in telemetry collection being suppressed for
248-
/// the current invocation
254+
/// the current invocation.
249255
///
250256
/// If you would like to permanently disable telemetry
251-
/// collection use `setTelemetry(false)`
257+
/// collection use:
258+
///
259+
/// ```dart
260+
/// analytics.setTelemetry(false)
261+
/// ```
252262
void suppressTelemetry();
253263

254-
/// Method to run after interacting with a [Survey]
264+
/// Method to run after interacting with a [Survey] instance.
255265
///
256266
/// Pass a [Survey] instance which can be retrieved from
257-
/// `fetchAvailableSurveys()`
267+
/// [Analytics.fetchAvailableSurveys].
258268
///
259-
/// [surveyButton] is the button that was interacted with by the user
269+
/// [surveyButton] is the button that was interacted with by the user.
260270
void surveyInteracted({
261271
required Survey survey,
262272
required SurveyButton surveyButton,
263273
});
264274

265-
/// Method to be called after a survey has been shown to the user
275+
/// Method to be called after a survey has been shown to the user.
266276
///
267-
/// Calling this will snooze the survey so it won't be shown immediately
277+
/// Calling this will snooze the survey so it won't be shown immediately.
268278
///
269279
/// The snooze period is defined by the [Survey.snoozeForMinutes] field.
270280
void surveyShown(Survey survey);
@@ -286,27 +296,27 @@ class AnalyticsImpl implements Analytics {
286296
/// Tells the client if they need to show a message to the
287297
/// user; this will return true if it is the first time the
288298
/// package is being used for a developer or if the consent
289-
/// message has been updated by the package
299+
/// message has been updated by the package.
290300
late bool _showMessage;
291301

292302
/// This will be switch to true once it has been confirmed by the
293-
/// client using this package that they have shown this message
294-
/// to the developer
303+
/// client using this package that they have shown the
304+
/// consent message to the developer.
295305
///
296306
/// If the tool using this package as already shown the consent message
297-
/// and it has been added to the config file, it will be set as true
307+
/// and it has been added to the config file, it will be set as true.
298308
///
299309
/// It will also be set to true once the tool using this package has
300-
/// invoked [clientShowedMessage]
310+
/// invoked [clientShowedMessage].
301311
///
302-
/// If this is false, all events will be blocked from being sent
312+
/// If this is false, all events will be blocked from being sent.
303313
bool _clientShowedMessage = false;
304314

305315
/// When set to `true`, various assert statements will be enabled
306-
/// to ensure usage of this class is within GA4 limitations
316+
/// to ensure usage of this class is within GA4 limitations.
307317
final bool _enableAsserts;
308318

309-
/// Telemetry suppression flag that is set via `suppressTelemetry()`
319+
/// Telemetry suppression flag that is set via [Analytics.suppressTelemetry].
310320
bool _telemetrySuppressed = false;
311321

312322
AnalyticsImpl({
@@ -399,18 +409,18 @@ class AnalyticsImpl implements Analytics {
399409
}
400410

401411
/// Checking the [telemetryEnabled] boolean reflects what the
402-
/// config file reflects
412+
/// config file reflects.
403413
///
404414
/// Checking the [_showMessage] boolean indicates if this the first
405415
/// time the tool is using analytics or if there has been an update
406416
/// the messaging found in constants.dart - in both cases, analytics
407-
/// will not be sent until the second time the tool is used
417+
/// will not be sent until the second time the tool is used.
408418
///
409-
/// Additionally, if the client has not invoked `clientShowedMessage`,
410-
/// then no events shall be sent.
419+
/// Additionally, if the client has not invoked
420+
/// [Analytics.clientShowedMessage], then no events shall be sent.
411421
///
412422
/// If the user has suppressed telemetry [_telemetrySuppressed] will
413-
/// return `true` to prevent events from being sent for current invocation
423+
/// return `true` to prevent events from being sent for current invocation.
414424
@override
415425
bool get okToSend =>
416426
telemetryEnabled &&

pkgs/unified_analytics/lib/src/asserts.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
/// Matches only alphabetic chars
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Matches only alphabetic characters.
26
final RegExp alphabeticPattern = RegExp(r'^[A-Za-z]+$');
37

4-
/// Matches strings that contain alphanumeric chars and underscores
8+
/// Matches strings that contain alphanumeric characters and underscores.
59
final RegExp alphaNumericPattern = RegExp(r'^[A-Za-z0-9_]+$');
610

711
/// Checks that the body of the request being sent to
8-
/// GA4 is within the limitations
12+
/// GA4 is within the limitations.
913
///
1014
/// Limitations can be found:
1115
/// https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events?client_type=gtag#limitations

pkgs/unified_analytics/lib/src/config_handler.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ import 'constants.dart';
1313
import 'initializer.dart';
1414
import 'utils.dart';
1515

16-
/// The regex pattern used to parse the disable analytics line
16+
/// The regex pattern used to parse the disable analytics line.
1717
const String telemetryFlagPattern = r'^reporting=([0|1]) *$';
1818

1919
/// The regex pattern used to parse the tools info
20-
/// from the configuration file
20+
/// from the configuration file.
2121
///
2222
/// Example:
23+
/// ```text
2324
/// flutter-tool=2022-10-26,1
25+
/// devtools=2022-11-26,1
26+
/// ```
2427
const String toolPattern =
2528
r'^([A-Za-z0-9]+[A-Za-z0-9_-]*)=([0-9]{4}-[0-9]{2}-[0-9]{2}),([0-9]+)$';
2629

2730
class ConfigHandler {
28-
/// Regex pattern implementation for matching a line in the config file
29-
///
30-
/// Example:
31-
/// flutter-tools=2022-10-26,1
31+
/// Regex pattern implementation for matching a line in the config file.
3232
static RegExp telemetryFlagRegex =
3333
RegExp(telemetryFlagPattern, multiLine: true);
3434
static RegExp toolRegex = RegExp(toolPattern, multiLine: true);
@@ -63,11 +63,11 @@ class ConfigHandler {
6363
parseConfig();
6464
}
6565

66-
/// Returns the telemetry state from the config file
66+
/// Returns the telemetry state from the config file.
6767
///
6868
/// Method will reparse the config file if it detects that the
6969
/// last modified datetime is different from what was parsed when
70-
/// the class was initialized
70+
/// the class was initialized.
7171
bool get telemetryEnabled {
7272
if (configFileLastModified.isBefore(configFile.lastModifiedSync())) {
7373
parseConfig();
@@ -79,7 +79,7 @@ class ConfigHandler {
7979

8080
/// Responsibe for the creation of the configuration line
8181
/// for the tool being passed in by the user and adding a
82-
/// [ToolInfo] object
82+
/// [ToolInfo] object.
8383
void addTool({
8484
required String tool,
8585
required int versionNumber,
@@ -103,7 +103,7 @@ class ConfigHandler {
103103

104104
/// Will increment the version number and update the date
105105
/// in the config file for the provided tool name while
106-
/// also incrementing the version number in [ToolInfo]
106+
/// also incrementing the version number in [ToolInfo].
107107
void incrementToolVersion({
108108
required String tool,
109109
required int newVersionNumber,
@@ -146,7 +146,7 @@ class ConfigHandler {
146146
/// Method responsible for reading in the config file stored on
147147
/// user's machine and parsing out the following: all the tools that
148148
/// have been logged in the file, the dates they were last run, and
149-
/// determining if telemetry is enabled by parsing the file
149+
/// determining if telemetry is enabled by parsing the file.
150150
void parseConfig() {
151151
// Begin with the assumption that telemetry is always enabled
152152
_telemetryEnabled = true;
@@ -182,14 +182,14 @@ class ConfigHandler {
182182
}
183183

184184
/// This will reset the configuration file and clear the
185-
/// [parsedTools] map and trigger parsing the config again
185+
/// [parsedTools] map and trigger parsing the config again.
186186
void resetConfig() {
187187
initializer.run(forceReset: true);
188188
parsedTools.clear();
189189
parseConfig();
190190
}
191191

192-
/// Disables the reporting capabilities if false is passed
192+
/// Disables the reporting capabilities if [reportingBool] is set to `false`.
193193
Future<void> setTelemetry(bool reportingBool) async {
194194
final flag = reportingBool ? '1' : '0';
195195
final configString = await configFile.readAsString();

0 commit comments

Comments
 (0)