官术网_书友最值得收藏!

Using Sublime Text 2 as an IDE

Dart Editor is a great environment, but Sublime Text also has many functionalities and can be used with many other languages, making it the preferred editor for many developers.

Getting ready

You can download Sublime Text free of cost for evaluation, however, for continued use, a license must be purchased from http://www.sublimetext.com/.

Tim Armstrong from Google developed a Dart plugin for Sublime Text, which can be downloaded from GitHub at Control plugin first by following the instructions at https://sublime.wbond.net/installation#st2.

How to do it...

In Sublime Text, press Ctrl + Shi ft + P (Windows or Linux) or Cmd + Shift + P (OS X; this goes for all the following commands), click on Install Package to choose that option, and then click and choose Dart to install the plugin. Any Dart file you then open shows the highlighted syntax, matching brackets, and so on.

Also, click on Menu Preferences, Settings, and then on User and add the path to your dart-sdk as the first line in this JSON file:

{
"dartsdk_path": "path\to\dart-sdk",
…
}

If you want to manually install this plugin, copy the contents of the dart-sublime-bundle-master folder to a new directory named Dart in the Sublime packages directory. This directory has different locations on different OS. They are as follows:

  • On Windows, this will likely be found at C:\Users\{your username}\AppData\Roaming\Sublime Text 2\Packages
  • On Linux, this will likely be found at $HOME/Sublime Text 2/Pristine Packages
  • On OSX, this will likely be found at ~/Library/Application Support/Sublime Text 2/Packages

How it works...

The plugin has a number of code snippets to facilitate working with Dart, for example, typing lib expands the library statement. Other snippets include imp for import, class for a class template, method for a method template, and main for a main() function. Typing a snippet in the pop-up window after pressing Ctrl + SHIFT + P lets you see a list of all the snippets. Use Ctrl + / to (un)comment the selected code text.

The plugin has also made a build system for you. Ctrl + B will invoke the dartanalyzer and then compile the Dart code to JavaScript with the dart2js compiler, as shown in the following screenshot. Editing and saving a pubspec.yaml file will automatically invoke the pub get command.

Working in Sublime Text 2

See also

  • Refer to the Configuring the Dart environment recipe for the path to the Dart SDK
主站蜘蛛池模板: 墨竹工卡县| 盐城市| 吉安市| 宁陕县| 黄大仙区| 色达县| 芜湖市| 手游| 信宜市| 缙云县| 尉犁县| 达拉特旗| 新丰县| 互助| 红安县| 正镶白旗| 临沭县| 武冈市| 张家港市| 安宁市| 宁乡县| 宜宾县| 定日县| 工布江达县| 康保县| 杨浦区| 土默特右旗| 德州市| 宁海县| 辽阳市| 合水县| 永顺县| 商城县| 光山县| 张家口市| 同德县| 宜州市| 广水市| 高淳县| 华池县| 阳新县|