无法访问 Dart 库中的私有方法

Can't access to a private method in Dart Library

我必须访问 Class 中的私有方法。我在 Class 中创建了一个库,导入它但它仍然无法识别。我对私有变量也有同样的问题。

示例:

文件buffer.dart:

    library buflib;

    class Buffer{

            void _record(){
                    [...]
            }

    }

在同一文件夹中:engine.dart

    import 'buffer.dart';

    class Engine {

            Buffer _buff = Buffer()

            [...]
            void myMethod(){
                    [...]
                    this._buff._record();
            }
    }

我有这个错误:

The method '_record' isn't defined for the type 'Buffer'. Try correcting the name to the name of an existing method, or defining >a method named '_record'.dartundefined_method

有什么建议吗? 谢谢

你不能从那里调用私有方法或变量 类 ....你应该通过删除“under score”

将其更改为 public

默认情况下,每个单独的 .dart 文件都是一个单独的库。由于私有标识符对图书馆来说是私有的,因此其他 .dart 文件将看不到它们。

您可以使用 librarypart of 指令将多个 .dart 文件分组到同一个库中,但是 those directives aren't documented.