[Flutter] Platform 정보를 확인하기 위한 방법 정리
2023. 4. 2. 11:52ㆍDevelopers 공간 [Shorts]/Frontend
728x90
반응형
<분류>
A. 수단
- OS/Platform/Tool : Linux, Kubernetes(k8s), Docker, AWS
- Package Manager : node.js, yarn, brew,
- Compiler/Transpillar : React, Nvcc, gcc/g++, Babel, Flutter
- Module Bundler : React, Webpack, Parcel
B. 언어
- C/C++, python, Javacsript, Typescript, Go-Lang, CUDA, Dart, HTML/CSS
C. 라이브러리 및 프레임워크 및 SDK
- OpenCV, OpenCL, FastAPI, PyTorch, Tensorflow, Nsight
1. What? (현상)
Flutter를 활용해 앱을 구현하다 보면 Platform의 버전 및 종류 등 다양한 정보를 구분해야하는 경우가 있습니다.
이를 한번에 정리해보고자 합니다.
2. Why? (원인)
- X
3. How? (해결책)
- App의 Orientation : portrait(세로 모드)인지 landscape(가로 모드)인지를 구분하기 위해 MediaQuery를 활용합니다.
if (MediaQuery.of(context).orientation == Orientation.portrait){ // is portrait }else{ // is landscape }
- Platform의 종류 : 웹인지, 안드로이드인지, iOS인지 등을 dart에 내장되어 있는 io 패키지를 활용하거나 get 패키지를 활용하여 구현할 수 있습니다.
import 'dart:io' show Platform; //Platform.isAndroid //Platform.isFuchsia //Platform.isIOS //Platform.isLinux //Platform.isMacOS //Platform.isWindows if (Platform.isAndroid) { // Android-specific code } else if (Platform.isIOS) { // iOS-specific code }
import 'package:get/get.dart'; bool isWeb = GetPlatform.isWeb; bool isMobile = GetPlatform.isMobile; bool isAndroid = GetPlatform.isAndroid; bool isiOS = GetPlatform.isIOS; bool isWeb = GetPlatform.isWeb; bool isWindows = GetPlatform.isWindows; bool isMac = GetPlatform.isMacOS; bool isLinux = GetPlatform.isLinux; bool isFusia = GetPlatform.isFuchsia; bool isDesktop = GetPlatform.isDesktop; if(!isWeb){ ... }
- Platform의 버전 확인 : device info 플러그인을 활용해 SDK 버전 혹은 ios 버전을 알아 낼 수 있습니다.
import 'package:device_info_plus/device_info_plus.dart'; if (Platform.isAndroid) { var androidInfo = await DeviceInfoPlugin().androidInfo; var release = androidInfo.version.release; var sdkInt = androidInfo.version.sdkInt; var manufacturer = androidInfo.manufacturer; var model = androidInfo.model; // Android 9 (SDK 28), Xiaomi Redmi Note 7 print('Android $release (SDK $sdkInt), $manufacturer $model'); } if (Platform.isIOS) { var iosInfo = await DeviceInfoPlugin().iosInfo; var systemName = iosInfo.systemName; var version = iosInfo.systemVersion; var name = iosInfo.name; var model = iosInfo.model; // iOS 13.1, iPhone 11 Pro Max iPhone print('$systemName $version, $name $model'); }
- Locale 확인 : UI에서 사용되는 언어, 지역 설정, 출력 형식 등을 정의하는 문자열
- 현재 상태
import 'dart:io' show Platform; // Returns locale string in the form 'en_US' String languageCode = Platform.localeName.split('_')[0]; String countryCode = Platform.localeName.split('_')[1];
import 'package:flutter_native_timezone/flutter_native_timezone.dart'; final String currentTimeZone = await FlutterNativeTimezone.getLocalTimezone();
- 시스템 셋팅
import 'package:flutter/material.dart'; // Returns the list of locales that user defined in the system settings. final List<Locale> systemLocales = WidgetsBinding.instance.window.locales;
import 'dart:ui'; final List<Locale> systemLocales = window.locales;
728x90
반응형
'Developers 공간 [Shorts] > Frontend' 카테고리의 다른 글
[Flutter] Geolocator 사용하기 (0) | 2023.04.03 |
---|---|
[Flutter] iOS 개발 시 나오는 다양한 ID 정리 (+signing 개념) (0) | 2023.04.02 |
[Flutter] Stacked에서 view와 viewModel의 생성 순서 (0) | 2023.04.02 |
[Flutter] 버튼에 애니메이션 넣기 (0) | 2023.03.28 |
[Flutter] Portrait, Landscape mode 막기 (0) | 2023.03.28 |