[英]Import dart file in flutter
I'm working on a flutter project and I want to import a dart file in my main file but I don't know how to do it.我正在处理一个 flutter 项目,我想在我的主文件中导入一个 dart 文件,但我不知道该怎么做。 I import my dart file first import 'package:splash/Categories.dart';
我首先导入我的 dart 文件import 'package:splash/Categories.dart';
and I initialized it like that final Category _category = Category();
然后我像final Category _category = Category();
but I have this error Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports
Please how can I fix it.但我有这个错误Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports
请问我该如何修复它。 Thank you in advance先感谢您
This happens when the same class is in two different files.当相同的 class 在两个不同的文件中时,就会发生这种情况。 So if you want to use a specific class in specific file we need to use aliases.因此,如果您想在特定文件中使用特定的 class,我们需要使用别名。
Example:例子:
import 'package:splash/Categories.dart';
import 'package:something/Something.dart' as name;
Use classname in Something.dart
as name.class_name在Something.dart
中使用类名作为name.class_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.