How do you detect the host platform from Dart code?

前端 未结 9 2210
情书的邮戳
情书的邮戳 2020-12-02 08:57

For UI that should differ slightly on iOS and Android, i.e. on different platforms, there must be a way to detect

9条回答
  •  粉色の甜心
    2020-12-02 09:34

    It is simple just import the io library

    import'dart:io' show Platform;
    void main(){
    if(Platform.isIOS){
      return someThing();
    }else if(Platform.isAndroid){
      return otherThing();
    }else if(Platform.isMacOS){
      return anotherThing();
    }
    

    or in very simple way

    Platform.isIOS ? someThing() : anOther(),
    

提交回复
热议问题