有没有办法在飞镖中实现内部 类 ?

Is there a way to implement inner classes in dart?

//access to a Constant if it was like another language 
ImageWeather.Desktop.cloud; 
 
//What i wanted ( not working because there is no inner class)
class ImageWeather {
      class Desktop {
         static const String cloud = 'assets/images/DesktopCloud.png';
         static const String noCloud = 'assets/images/DesktopNoCloud.png';
         static const String rain = 'assets/images/DesktopRain.png';
   }  
      class Phone{
         static const String cloud = 'assets/images/PhoneCloud.png';
         static const String noCloud = 'assets/images/PhoneNoCloud.png';
         static const String rain = 'assets/images/PhoneRain.png';
   }
}

//access to a String like an inner class with new code
ImageWeather.desktop.cloud;


class ImageWeather {
   static final Desktop desktop = Desktop();
   static final Phone phone = Phone();
}

class Desktop {
   get cloud => 'assets/images/DesktopCloud.png';
   get noCloud => 'assets/images/DesktopNoCloud.png';
   get rain => 'assets/images/DesktopRain.png';
}
class Phone {
   get cloud => 'assets/images/PhoneCloud.png';
   get noCloud => 'assets/images/PhoneNoCloud.png';
   get rain => 'assets/images/PhoneRain.png';

}

我目前正在学习 Dart,但我发现我无法使用内部 class。 有没有办法在 Dart 中编写类似于 inner classes 的东西?

使用 Inner 类 是好是坏是主观的。不同的开发者会有不同的看法。

但是,如果您希望 DesktopPhone 只对 ImageWeather 可见,您可以将三个 类 写在一个包中,并将 Phone 重命名为 'inner' 类 _Desktop_Phone,从而使它们仅在该包内可见。