📱 Mobile/📱 (old) Flutter v 1.0
dart.io 패키지를 활용한 플랫폼(iOS, Android) 감지하기
DarrenKwonDev
2020. 5. 23. 04:29
dart.io의 platform.dart의 Platform 클래스를 이용해서 플랫폼을 감지할 수 있다. 이를 이용해서 iOS환경에서는 쿠퍼티노를 사용해보도록 하자.
🚀 import의 기술
import 'dart:io' show Platform; // Platform 클래스만 씀
import 'dart:io' hide Platform; // Platform 클래스만 빼고 씀
import 'dart:io' as Platform; // Platform 이란 이름으로 dart:io를 활용함
🚀 Platfrom.is... 를 사용하여 플랫폼 감지
import 'dart:io' show Platform;
DropdownButton androidDropDownButton() {
return DropdownButton<String>(
value: selectedCur,
items: currenciesList
.map((currency) => DropdownMenuItem(
child: Text(currency),
value: currency,
))
.toList(),
onChanged: (value) {
setState(() {
selectedCur = value;
});
},
);
}
CupertinoPicker iOSPicker() {
return CupertinoPicker(
backgroundColor: Colors.lightBlue,
itemExtent: 38.0,
onSelectedItemChanged: (int selectedIndex) {
print(selectedIndex);
},
children: currenciesList.map((currency) => Text(currency)).toList(),
);
}
getPicker() {
if (Platform.isIOS) {
return iOSPicker();
} else if (Platform.isAndroid) {
return androidDropDownButton();
}
}