Skip to content

Instantly share code, notes, and snippets.

@AndrewDongminYoo
Created March 21, 2025 13:40
Show Gist options
  • Save AndrewDongminYoo/2ebe09f4c42fa10bf908c8bc7c98cc16 to your computer and use it in GitHub Desktop.
Save AndrewDongminYoo/2ebe09f4c42fa10bf908c8bc7c98cc16 to your computer and use it in GitHub Desktop.
현재 플랫폼을 감지하는 유틸리티 메서드를 제공합니다.
// 🐦 Flutter imports:
import 'package:flutter/foundation.dart';
// 📦 Package imports:
import 'package:device_info_plus/device_info_plus.dart';
// 🌎 Project imports:
import 'platform_utils.dart';
/// 현재 플랫폼을 감지하는 유틸리티 메서드를 제공합니다.
class DeviceInfoService {
DeviceInfoService(this._plugin);
final DeviceInfoPlugin _plugin;
String? _cachedDeviceInfo;
Future<String> getDeviceInfo() async {
if (_cachedDeviceInfo != null) {
return _cachedDeviceInfo!;
}
final deviceInfo = await PlatformUtil.select(
ios: () => _plugin.iosInfo.then((IosDeviceInfo data) {
return data.modelName;
}),
android: () => _plugin.androidInfo.then((AndroidDeviceInfo data) {
return '${data.brand} ${data.device}'.toTitleCase();
}),
web: () => _plugin.webBrowserInfo.then((WebBrowserInfo data) {
return data.browserName.name.toTitleCase();
}),
);
_cachedDeviceInfo = deviceInfo;
return deviceInfo;
}
@visibleForTesting
void clearDeviceInfoCache() {
_cachedDeviceInfo = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment