Created
March 21, 2025 13:40
-
-
Save AndrewDongminYoo/2ebe09f4c42fa10bf908c8bc7c98cc16 to your computer and use it in GitHub Desktop.
현재 플랫폼을 감지하는 유틸리티 메서드를 제공합니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 🐦 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