How do you detect the host platform from Dart code?

前端 未结 9 2209
情书的邮戳
情书的邮戳 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:29

    Most "Flutter" answer is as follows:

    import 'package:flutter/foundation.dart' show TargetPlatform;
    
    //...
    
    if(Theme.of(context).platform == TargetPlatform.android)
        //do sth for Android
    else if(Theme.of(context).platform == TargetPlatform.iOS)
        //do sth else for iOS
    else if(Theme.of(context).platform == TargetPlatform.fuchsia)
        //even do sth else for Fuchsia OS
    

提交回复
热议问题