Câu hỏi phỏng vấn Flutter
Câu hỏi

What does a class with a method ...

Câu trả lời

In Dart, a class with a method named ._() is typically used to create a singleton class. A singleton is a design pattern that restricts the instantiation of a class to one object. Here's how it works:

dart Copy
class AppTheme {
  AppTheme._(); // Private constructor

  static const Color notWhite = Color(0xFFEDF0F2);
  static const Color nearlyWhite = Color(0xFFFEFEFE);
  // ...
}
  1. The class has a private constructor named ._(). The leading underscore _ makes the constructor private, meaning it can only be accessed within the same library[1].

  2. The private constructor prevents the class from being instantiated directly using the new keyword or a constructor call[1][2].

  3. The class usually has static members, such as constants or methods, that can be accessed without creating an instance of the class[1].

  4. To get an instance of the singleton class, you typically provide a static method that returns...

senior

senior

Gợi ý câu hỏi phỏng vấn

junior

How is Flutter different from a WebView based application?

expert

How is AnimationController different from Timer ?

middle

Why is the build() method on State and not Stateful Widget?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào