How can I detect if my Flutter app is running in the web?

后端 未结 2 683
遇见更好的自我
遇见更好的自我 2021-02-03 18:10

I know that I can detect the operating system with Platform.isAndroid, Platform.isIOS, etc. but there isn\'t something like Platform.isWeb

相关标签:
2条回答
  • 2021-02-03 18:19

    There is a code written Below to get OS/web where flutter is running...

    if(kIsWeb)
       return Text("It's web");
    
    else if(Platform.isAndroid){
         return Text("it's Android"); }
    
    0 讨论(0)
  • 2021-02-03 18:27

    There is a global boolean kIsWeb which can tell you whether or not the app was compiled to run on the web.

    Documentation: https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html

    import 'package:flutter/foundation.dart' show kIsWeb;
    
    if (kIsWeb) {
      // running on the web!
    } else {
      // NOT running on the web! You can check for additional platforms here.
    }
    
    0 讨论(0)
提交回复
热议问题