I have to access to a private method in a Class. I created a library with inside the Class, imported it but it can't still recognize. I have the same problem also with private variables.
Example:
file buffer.dart :
library buflib;
class Buffer{
void _record(){
[...]
}
}
in the same folder: engine.dart
import 'buffer.dart';
class Engine {
Buffer _buff = Buffer()
[...]
void myMethod(){
[...]
this._buff._record();
}
}
I have this error:
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
Any suggestions? Thanks
u cant call private methods or variables from out there classes.... u should change it to public by removing "under score"
By default, each separate .dart
file is a separate library. Since private identifiers are private to the library, they won't be visible to other .dart
files.
You can use the library
and part of
directives to group multiple .dart
files into the same library, but those directives aren't documented .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.