简体   繁体   English

在 flutter 中使用标志

[英]Using flags in flutter

I have been searching if there are any packages in Flutter that can allow you to create flags to decide whether you run (or not) part of your code depending on if you want to make a debug build or a release build.我一直在搜索 Flutter 中是否有任何软件包可以让您创建标志来决定是否运行(或不运行)部分代码,具体取决于您是要进行调试构建还是发布构建。

There are some features I systematically want to have when I run my app in debug, but that I don't want to have in my release build.当我在调试中运行我的应用程序时,我系统地希望拥有一些功能,但我不想在我的发布版本中拥有这些功能。

I have tried flagsmith which allow me to create flags which I can enable or disable manually (which isn't exactly what I want), but it doesn't seem to even work properly as I disable / enable the flag there is no hiding/showing my features dynamically.我已经尝试过flagsmith ,它允许我创建可以手动启用或禁用的标志(这不是我想要的),但它似乎甚至无法正常工作,因为我禁用/启用了没有隐藏的标志/动态显示我的功能。

My question: is there a tool, for flutter, which can allow me to create flags that run code depending I create a debug build or a release build?我的问题:是否有一个用于 flutter 的工具,它可以让我根据我创建调试版本或发布版本来创建运行代码的标志?

You can use kDebugMode to check whether your code is running in debug mode.您可以使用kDebugMode检查您的代码是否在调试模式下运行。

Example:例子:

import 'package:flutter/foundation.dart';
void foobar() {
  if (kDebugMode) {
    // Do something only in debug mode...
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM