I read in a comment on a similar question for C# that extension methods can only be called from instances. Is the same true for Dart? I'm trying to add a getter to the Platform
class that will be called like so. Platform.isDesktop
. However, this only works when calling an instance of the class, i.e. Platform().isDesktop
, even if declaring the instance method as static. Why can't we add static members?
Code:
extension on Platform {
bool get isMobile => Platform.isAndroid || Platform.isIOS;
bool get isDesktop => Platform.isWindows || Platform.isMacOS || Platform.isLinux;
}