@@ -13,6 +13,7 @@ import 'enums.dart';
1313import 'exception.dart';
1414import 'interceptor.dart';
1515import 'response.dart';
16+ import 'package:flutter/foundation.dart';
1617
1718ClientBase createClient({
1819 required String endPoint,
@@ -124,27 +125,32 @@ class ClientIO extends ClientBase with ClientMixin {
124125 //creating custom user agent
125126 DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
126127 var device = '';
127- if (Platform.isAndroid) {
128- final andinfo = await deviceInfoPlugin.androidInfo;
129- device =
130- '(Linux; U; Android ${andinfo.version.release}; ${andinfo.brand} ${andinfo.model})';
131- }
132- if (Platform.isIOS) {
133- final iosinfo = await deviceInfoPlugin.iosInfo;
134- device = '${iosinfo.utsname.machine} iOS/${iosinfo.systemVersion}';
135- }
136- if (Platform.isLinux) {
137- final lininfo = await deviceInfoPlugin.linuxInfo;
138- device = '(Linux; U; ${lininfo.id} ${lininfo.version})';
139- }
140- if (Platform.isWindows) {
141- final wininfo = await deviceInfoPlugin.windowsInfo;
142- device =
143- '(Windows NT; ${wininfo.computerName})'; //can't seem to get much info here
144- }
145- if (Platform.isMacOS) {
146- final macinfo = await deviceInfoPlugin.macOsInfo;
147- device = '(Macintosh; ${macinfo.model})';
128+ try {
129+ if (Platform.isAndroid) {
130+ final andinfo = await deviceInfoPlugin.androidInfo;
131+ device =
132+ '(Linux; U; Android ${andinfo.version.release}; ${andinfo.brand} ${andinfo.model})';
133+ }
134+ if (Platform.isIOS) {
135+ final iosinfo = await deviceInfoPlugin.iosInfo;
136+ device = '${iosinfo.utsname.machine} iOS/${iosinfo.systemVersion}';
137+ }
138+ if (Platform.isLinux) {
139+ final lininfo = await deviceInfoPlugin.linuxInfo;
140+ device = '(Linux; U; ${lininfo.id} ${lininfo.version})';
141+ }
142+ if (Platform.isWindows) {
143+ final wininfo = await deviceInfoPlugin.windowsInfo;
144+ device =
145+ '(Windows NT; ${wininfo.computerName})'; //can't seem to get much info here
146+ }
147+ if (Platform.isMacOS) {
148+ final macinfo = await deviceInfoPlugin.macOsInfo;
149+ device = '(Macintosh; ${macinfo.model})';
150+ }
151+ } catch (e) {
152+ debugPrint('Error getting device info: $e');
153+ device = Platform.operatingSystem;
148154 }
149155 addHeader(
150156 'user-agent', '${packageInfo.packageName}/${packageInfo.version} $device');
0 commit comments