在 flutter 中导入 dart 文件
Import dart file in flutter
我正在做一个 flutter 项目,我想在我的主文件中导入一个 dart 文件,但我不知道该怎么做。
我先导入我的飞镖文件 import 'package:splash/Categories.dart';
然后我就这样初始化了它 final Category _category = Category();
但是我有这个错误 Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports
请问我该如何解决。提前谢谢你
当相同的 class 在两个不同的文件中时,会发生这种情况。因此,如果您想在特定文件中使用特定的 class,我们需要使用别名。
示例:
import 'package:splash/Categories.dart';
import 'package:something/Something.dart' as name;
在Something.dart
中使用class名字作为name.class_name
我正在做一个 flutter 项目,我想在我的主文件中导入一个 dart 文件,但我不知道该怎么做。
我先导入我的飞镖文件 import 'package:splash/Categories.dart';
然后我就这样初始化了它 final Category _category = Category();
但是我有这个错误 Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports
请问我该如何解决。提前谢谢你
当相同的 class 在两个不同的文件中时,会发生这种情况。因此,如果您想在特定文件中使用特定的 class,我们需要使用别名。
示例:
import 'package:splash/Categories.dart';
import 'package:something/Something.dart' as name;
在Something.dart
中使用class名字作为name.class_name