[flutter] pass device to flutter command

test: manual

Read the device name from the fx config and pass it to flutter attach so that it works when multiple devices are connected. Also sets the working directory to the fuchsia root, which the fluter tool expects

Change-Id: I4142a4dac42aa9b99da78d1739d652169ade5290
diff --git a/devshell/flutter-attach b/devshell/flutter-attach
index d470c41..3e78c4b 100755
--- a/devshell/flutter-attach
+++ b/devshell/flutter-attach
@@ -17,6 +17,13 @@
 source "${DEVSHELL_DIR}"/lib/vars.sh
 fx-config-read
 
+ARGS=()
+
+NAME="$(get-device-name)"
+if [[ -n "$name" ]]; then
+  ARGS+=("--device", "${name}")
+fi
+
 for var in "$@"
 do
   case "$var" in
@@ -25,7 +32,7 @@
       exit 0
     ;;
     -v|--verbose)
-      VERBOSE="--verbose"
+      ARGS+=("--verbose")
     ;;
     *)
       TARGET="$var"
@@ -46,11 +53,14 @@
   >&2 echo "PRREBUILT DART binary not supported on current platform"
   exit 1
 fi
-  
+
 FUCHSIA_ATTACH_BIN="${FUCHSIA_BUILD_DIR}/host_x64/dart-tools/fuchsia_attach"
 
+# The flutter tool expects the working directory is the fuchsia root.
+cd "${FUCHSIA_DIR}"
+
 "${FUCHSIA_ATTACH_BIN}" \
   "--dart-sdk=${PREBUILT_DART}" \
   "--build-dir=${FUCHSIA_BUILD_DIR}"\
   "--target=${TARGET}" \
-  "${VERBOSE}"
+  "${ARGS[@]}"