What is package naming convention used in Dart?

和自甴很熟 提交于 2020-02-23 08:51:28

问题


Is there a naming convention for Dart packages? Is there maybe a document that describes patterns? I have trouble figuring out naming convention for package names that consist of multiple words. For example, should I use placeView, PlaceView, place_view, or something else?


回答1:


This is documented on the name section of Pubspec Format documentation.

It should be all lowercase, with underscores to separate words, just_like_this. Stick with basic Latin letters and Arabic digits: [a-z0-9_] and ensure that it’s a valid Dart identifier (i.e. doesn’t start with digits and isn’t a reserved word).

Try to pick a name that is clear, terse, and not already in use.




回答2:


There doesn't seem to be a convention for it, but most of the time, I see lowercase_words_with_underscore being used, both for libraries and packages.

For libraries inside packages, some people also use dots for grouping, for example my_package.lib_1 and my_package.lib_2.

It's all personal preference, I guess.




回答3:


All the package conventions are documented on pub.dartlang.org. The package naming conventions in particular are documented on the pubspec format page.




回答4:


I only found this https://code.google.com/p/dart/issues/detail?id=5094

  • That the package name follows the naming conventions (valid Dart identifier, doesn't conflict with any reserved words, all lower case).



回答5:


You only can create flutter project by lowercase and no space between the project name and avoid to add special characters. Follow these steps you will not get any error like this.

"ProjectName" is not a valid Dart package name.


From the [Pubspec format description](https://www.dartlang.org/tools/pub/pubspec.html):

**DO** use `lowercase_with_underscores` for package names.

Package names should be all lowercase, with underscores to separate words,
`just_like_this`.  Use only basic Latin letters and Arabic digits: [a-z0-9_].
Also, make sure the name is a valid Dart identifier -- that it doesn't start
with digits and isn't a reserved word.


来源:https://stackoverflow.com/questions/21401244/what-is-package-naming-convention-used-in-dart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!