Junior — Middle
What types of visibility modifiers exist in Dart?
sobes.tech AI
Answer from AI
In Dart, there is one main way to modify the visibility level — using the underscore prefix before the name of a variable, method, or class. If the name starts with an underscore (_), then this element becomes private to the library (file) in which it is declared.
Example:
class MyClass {
int _privateValue = 42; // private field
void _privateMethod() { // private method
print('This is a private method');
}
void publicMethod() {
print('This is a public method');
}
}
In Dart, there are no keywords like public, private, or protected as in other languages. Visibility is limited to the library, not the class or inheritance.