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