Skip to content

Commit

Permalink
Add flutter-run-device
Browse files Browse the repository at this point in the history
Closes #28
  • Loading branch information
jcs090218 authored and amake committed Aug 11, 2023
1 parent 983f1ec commit 36ee096
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions flutter.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
;;; Code:

(require 'comint)
(require 'json)
(require 'flutter-project)
(require 'flutter-l10n)

Expand Down Expand Up @@ -261,6 +262,23 @@ args."
args
(display-buffer buffer)))

(defun flutter-devices ()
"Return an alist of devices in (name . ID) format."
(let* ((output (shell-command-to-string "flutter devices --machine"))
(vec (json-read-from-string output)))
(mapcar
(lambda (alist) (let-alist alist (cons .name .id)))
vec)))

;;;###autoload
(defun flutter-run-device (device-id)
"Start `flutter run` with DEVICE-ID."
(interactive
(list (let* ((collection (flutter-devices))
(choice (completing-read "Device: " collection)))
(cdr (assoc choice collection)))))
(flutter-run (format "-d %s" device-id)))

;;;###autoload
(defun flutter-run-or-hot-reload ()
"Start `flutter run` or hot-reload if already running."
Expand Down

0 comments on commit 36ee096

Please sign in to comment.