【问题标题】:How can I disable some functionality only if web on Flutter app?只有在 Flutter 应用程序上使用 Web 时,如何才能禁用某些功能?
【发布时间】:2020-05-27 18:14:01
【问题描述】:

我看到今天 Flutter 有一个测试版 web support。但是,如果我有一些观点或一般情况下仅支持移动设备的某些功能,那么如何仅在我为 Web 构建时才禁用它?有可能吗?

【问题讨论】:

    标签: flutter dart web flutter-web


    【解决方案1】:
    import 'package:flutter/foundation.dart';
    
    if (kIsWeb) {
      // running on the web!
    } else {
      // NOT running on the web! You can check for additional platforms here.
    }
    

    此外,如果您想检查内部小部件而不显示移动小部件

    child: kIsWeb ? Container():<Mobile Widget>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 2011-03-14
      相关资源
      最近更新 更多