Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用pub serve运行dart应用程序时,将自定义参数传递给dart应用程序_Dart_Dart Pub - Fatal编程技术网

使用pub serve运行dart应用程序时,将自定义参数传递给dart应用程序

使用pub serve运行dart应用程序时,将自定义参数传递给dart应用程序,dart,dart-pub,Dart,Dart Pub,在使用pub-serve运行dart应用程序时,是否可以将一些参数传递给dart应用程序?我想做的是让应用程序在开发时使用一些模拟服务,但在部署时,我想用真实的服务替换模拟服务。例如: const bool DEBUG=true; 类AppModule扩展模块{ AppModule(){ 类型(PaymentService,实现者:DEBUG?PaymapPaymentService:MockPaymentService); } } 我希望这个调试参数以某种方式来自环境,并且在使用pub-se

在使用
pub-serve
运行dart应用程序时,是否可以将一些参数传递给dart应用程序?我想做的是让应用程序在开发时使用一些模拟服务,但在部署时,我想用真实的服务替换模拟服务。例如:

const bool DEBUG=true;
类AppModule扩展模块{
AppModule(){
类型(PaymentService,实现者:DEBUG?PaymapPaymentService:MockPaymentService);
}
}

我希望这个调试参数以某种方式来自环境,并且在使用
pub-serve
运行应用程序时易于配置。实现这一点的最佳方法是什么?

您可以查看URL。如果
host
在开发环境中是
127.0.0.1
your,否则它是prod

另一个想法是使用一个转换器,当
模式
调试
时,它会注入一些东西。 不确定这样做是否真的可行

$ pub help serve
Run a local web development server.

Usage: pub serve
-h, --help               Print usage information for this command.
    --port               The port to listen on.
                         (defaults to "8080")

    --[no-]dart2js       Compile Dart to JavaScript.
                         (defaults to on)

    --[no-]force-poll    Force the use of a polling filesystem watcher.
    --mode               Mode to run transformers in.
                         (defaults to "debug")

URL不起作用,因为我可能会在本地主机上使用真实服务的模式下运行应用程序。变形金刚可能会工作,但我找不到一个如何编写变形金刚的例子。有什么建议吗?pub上的文档没有显示如何编写一个转换器,只显示如何使用它。最近有一次讨论,应该编写一个文档,说明如何构建一个转换器,但还没有看到。()另外,当我运行pub-serve时,如何指定这是“生产”模式还是“调试”模式?我在寻找类似于
pub-service--mode=debug
的东西。我将
pub-help-service
的输出添加到我的答案中<代码>--mode=debug是默认值。哦。。。对不起,我没有意识到酒吧已经有了一个名为“mode”的标志。我想传递一个自定义标志(巧合的是,我使用了已经存在的名称模式)。也许更好的例子是'pub-service--app_mode=debug'。我正在考虑在html中设置一个元标记,然后阅读它来设置模式。。。然后,如果需要,我可以在部署过程中使用transformer来实际更改值。。。。