dart导入和同一文件中的部分指令 [英] dart import and part of directives in same file

查看:138
本文介绍了dart导入和同一文件中的部分指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个飞镖文件:

I'm writing a dart file:

import 'something.dart'

part of my_lib;

class A{
    //...
}

我试过这个用 import 部分的指令反转了它仍然无效,你有没有一个类文件作为库的一部分并且有导入?

I have tried this with the import and part of directives reversed and it still won't work, can you not have a class file as part of a library and have imports?

推荐答案

所有的导入应该放在那个文件中定义库。

All your imports should go in the file that defines the library.

库:

library my_lib;

import 'something.dart';

part 'a.dart';

class MyLib {
  //...
}

a.dart

part of my_lib;

class A {
  //...
}

由于a.dart是my_lib的一部分,因此它可以访问my_lib导入的任何文件。

Since a.dart is part of my_lib it will have access to any files that my_lib imports.

这篇关于dart导入和同一文件中的部分指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆