Emacs tools for working with the Flutter SDK
Run your app
Flutter.el helps you run the
flutter binary interactively as an inferior
process. It's designed to work together with
dart-mode: for instance the example
configuration below binds
flutter-run-or-hot-reload to C-M-x in
dart-mode. While editing your Dart code, just hit C-M-x to either
run your app, or if it's already running, to hot-reload it.
Localize your app
Any non-trivial app will require localization, but if you're like me you probably write your code first and worry about externalizing your strings (moving their definitions to a separate file) later.
Flutter.el comes with some helpful features to make externalizing strings easier, assuming you are following best practices:
flutter-l10n-externalize-all: A function that interactively does the following for each string literal in the current buffer:
- Prompts you to give an ID (class property name) to the string,
- Replaces the string literal with a reference to the localizations class,
- Deletes any
constkeywords that apply to the reference
- Appends the original string content as an end-of-line comment
- Appends a definition for the string to the localizations class, e.g.
String get myString => Intl.message('Hello, world!', name: 'myString');
- Prompts you to give an ID (class property name) to the string, e.g.
flutter-l10n-externalize-at-point: Does all of the above but for the string literal at point only; kills the definition instead of adding it to the localizations class.
Lint your localization strings
A Flycheck checker calling
intl_translation:extract_to_arb from the
intl_translation package is
available for making sure your strings are defined in the correct way. This is
published as a separate, optional package: flutter-l10n-flycheck.
You can install from MELPA with
M-x package-install flutter
M-x package-install flutter-l10n-flycheck
flutter-sdk-path to the location of your Flutter SDK. This isn't even
necessary if the
flutter binary is on your
To use the localization tools you will want to customize these variables for your project:
flutter-l10n-classname: The name of the localizations class where strings are defined
flutter-l10n-file: The relative path from project root to the file that defines the localizations class. Should include the leading
If using flutter-l10n-flycheck be sure to call
set your L10N file (the one specified in
flutter-l10n-file) to use the
M-x add-file-local-variable-prop-line flycheck-checker intl_translation
use-package and assuming you
put the Flutter SDK in
;; Assuming usage with dart-mode (use-package dart-mode :ensure-system-package (dart_language_server . "pub global activate dart_language_server") :custom (dart-format-on-save t) (dart-sdk-path "/Applications/flutter/bin/cache/dart-sdk/")) (use-package flutter :after dart-mode :bind (:map dart-mode-map ("C-M-x" . #'flutter-run-or-hot-reload)) :custom (flutter-sdk-path "/Applications/flutter/")) ;; Optional (use-package flutter-l10n-flycheck :after flutter :config (flutter-l10n-flycheck-setup))
.dir-locals.el to go in your project root:
((dart-mode (flutter-l10n-classname . "AppLocalizations") (flutter-l10n-file . "lib/app_l10n.dart")))
The propline for your L10N file:
// -*- flycheck-checker: intl_translation; -*-