What is an extension in Dart?
Why Interviewers Ask This
This question targets practical, hands-on experience with Flutter. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
Answer
Extensions allow you to add new methods to existing types without modifying their source code or using inheritance. Declare an extension with extension StringUtils on String { ... } and then call its methods on any String. For example: extension on DateTime { bool get isToday => day == DateTime.now().day; }. Extensions are resolved statically at compile time and do not actually modify the original class. They are widely used to add utility helpers to built-in types like String, List, and DateTime.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Flutter project, I used this when...' immediately makes your answer more credible and memorable.