我可以根据调试或发布模式有条件地导入吗?

时间:2020-09-08 23:01:49

标签: flutter dart

问题

由于一个库会在编译时破坏调试版本,因此我需要删除 debug builds 的导入。如果感兴趣的话,则是a Flutter web one

什么有效

我知道基于库的条件导入有效(请参见article):

import 'one_thing.dart'
  if (dart.library.io) 'another_thing.dart'
  if (dart.library.js) 'another_thing.dart'
  if (dart.library.html) 'another_thing.dart';

我需要什么

这些库条件对我没有帮助,因为我的构建仍将无法在调试模式下编译。

理想情况下,我会遇到这样的事情:

import 'one_thing.dart'
  if (kDebugMode) 'another_thing.dart';

但是,由于条件仅允许Dart VM条件并且kDebugMode是Flutter中定义的常量,因此该方法不起作用。

问题

如何在调试模式下删除/阻止库的导入

0 个答案:

没有答案