@@ -215,6 +215,34 @@ bool legacyOptOut({required FileSystem fs, required Directory home}) {
215
215
return false ;
216
216
}
217
217
218
+ /// Helper method that can be used to resolve the Dart SDK version for clients
219
+ /// of package:unified_analytics.
220
+ ///
221
+ /// Input [versionString] for this method should be the returned string from
222
+ /// [io.Platform.version] .
223
+ ///
224
+ /// For tools that don't already have a method for resolving the Dart
225
+ /// SDK version in semver notation, this helper can be used. This uses
226
+ /// the [io.Platform.version] to parse the semver.
227
+ ///
228
+ /// Example for stable version:
229
+ /// `3.3.0 (stable) (Tue Feb 13 10:25:19 2024 +0000) on "macos_arm64"` into
230
+ /// `3.3.0` .
231
+ ///
232
+ /// Example for non-stable version:
233
+ /// `2.1.0-dev.8.0.flutter-312ae32` into `2.1.0 (build 2.1.0-dev.8.0 312ae32)` .
234
+ String parseDartSDKVersion (String versionString) {
235
+ versionString = versionString.trim ();
236
+ final justVersion = versionString.split (' ' )[0 ];
237
+
238
+ // For non-stable versions, this regex will include build information
239
+ return justVersion.replaceFirstMapped (RegExp (r'(\d+\.\d+\.\d+)(.+)' ),
240
+ (Match match) {
241
+ final noFlutter = match[2 ]! .replaceAll ('.flutter-' , ' ' );
242
+ return '${match [1 ]} (build ${match [1 ]}$noFlutter )' .trim ();
243
+ });
244
+ }
245
+
218
246
/// Will use two strings to produce a double for applying a sampling
219
247
/// rate for [Survey] to be returned to the user.
220
248
double sampleRate (String string1, String string2) =>
0 commit comments