diff --git a/packages/neon/neon/lib/src/utils/user_agent.dart b/packages/neon/neon/lib/src/utils/user_agent.dart index f8f924ae..3685dcc1 100644 --- a/packages/neon/neon/lib/src/utils/user_agent.dart +++ b/packages/neon/neon/lib/src/utils/user_agent.dart @@ -1,8 +1,11 @@ import 'package:meta/meta.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 void buildUserAgent(final PackageInfo packageInfo) { var buildNumber = packageInfo.buildNumber; @@ -12,5 +15,13 @@ void buildUserAgent(final PackageInfo packageInfo) { _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 -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!; +}