我有两个名为
的文件 abc.dart
String one = "One";
String two = "Two";
和xyz.dart
String one = "1";
String two = "2";
在我的应用中,我有一个bool
值,如果它是true
,我想将one
用作"One"
,并且如果false
,{{ 1}}应该是one
。
那是我需要导入"1"
上的abc.dart
和true
上的xyz.dart
。
答案 0 :(得分:0)
根据此issue,在Flutter中似乎不可能。
这是因为Flutter应用程序是在AOT(提前)的情况下编译的,因此它需要在编译时加载所有源。
因此,您不必选择依靠动态模块导入,而是:
// letter.dart
class Letters {
final String one;
final String two;
const Letter(this.one, this.two);
}
// abc.dart
const ABC = Letters('one', two');
// xyz.dart
const XYZ = Letters('1', 2');
// main
import './abc.dart'
import './xyz.dart'
onPressedHandler() {
print(boolValue? abc.one : xyz.one);
}