Browse Source

refactor(neon): throw an error if neonUserAgent hasn't been set up

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/886/head
Nikolas Rimikis 1 year ago
parent
commit
12f5fd2c0a
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 15
      packages/neon/neon/lib/src/utils/user_agent.dart

15
packages/neon/neon/lib/src/utils/user_agent.dart

@ -1,8 +1,11 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
late String? _userAgent; String? _userAgent;
/// Sets the user agent.
///
/// It can be accessed with [neonUserAgent].
@internal @internal
void buildUserAgent(final PackageInfo packageInfo) { void buildUserAgent(final PackageInfo packageInfo) {
var buildNumber = packageInfo.buildNumber; var buildNumber = packageInfo.buildNumber;
@ -12,5 +15,13 @@ void buildUserAgent(final PackageInfo packageInfo) {
_userAgent = 'Neon ${packageInfo.version}+$buildNumber'; _userAgent = 'Neon ${packageInfo.version}+$buildNumber';
} }
/// Gets the current user agent.
///
/// It must be set by calling [buildUserAgent] before. If not set a [StateError] will be thrown.
@internal @internal
String get neonUserAgent => _userAgent!; String get neonUserAgent {
if (_userAgent == null) {
throw StateError('The user agent has not been set up. Please use `buildUserAgent` before.');
}
return _userAgent!;
}

Loading…
Cancel
Save