Look for Flutter packages in bin/cache/pkg/ as well as packages/ (#1778)

Closes #1775
diff --git a/lib/src/flutter.dart b/lib/src/flutter.dart
index cd075ab..a4198e4 100644
--- a/lib/src/flutter.dart
+++ b/lib/src/flutter.dart
@@ -26,6 +26,11 @@
 }();
 
 /// Returns the path to the package [name] within Flutter.
+///
+/// Flutter packages exist in both `$flutter/packages` and
+/// `$flutter/bin/cache/pkg`. This checks both locations in order. If [name]
+/// exists in neither place, it returns the `$flutter/packages` location which
+/// is more human-readable for error messages.
 String packagePath(String name) {
   if (!isAvailable) {
     throw new ApplicationException(
@@ -34,5 +39,11 @@
         'pub through the "flutter" executable.');
   }
 
-  return p.join(rootDirectory, 'packages', name);
+  var packagePath = p.join(rootDirectory, 'packages', name);
+  if (dirExists(packagePath)) return packagePath;
+
+  var cachePath = p.join(rootDirectory, 'bin', 'cache', 'pkg', name);
+  if (dirExists(cachePath)) return cachePath;
+
+  return packagePath;
 }
diff --git a/test/sdk_test.dart b/test/sdk_test.dart
index 1e144e1..700db19 100644
--- a/test/sdk_test.dart
+++ b/test/sdk_test.dart
@@ -24,6 +24,10 @@
             d.libDir('foo', 'foo 0.0.1'),
             d.libPubspec('foo', '0.0.1', deps: {'bar': 'any'})
           ])
+        ]),
+        d.dir('bin/cache/pkg', [
+          d.dir('baz',
+              [d.libDir('baz', 'foo 0.0.1'), d.libPubspec('baz', '0.0.1')])
         ])
       ]).create();
     });
@@ -44,6 +48,21 @@
       ]).validate();
     });
 
+    test("gets an SDK dependency from bin/cache/pkg", () async {
+      await d.appDir({
+        "baz": {"sdk": "flutter"}
+      }).create();
+      await pubCommand(command,
+          environment: {'FLUTTER_ROOT': p.join(d.sandbox, 'flutter')});
+
+      await d.dir(appPath, [
+        d.packagesFile({
+          'myapp': '.',
+          'baz': p.join(d.sandbox, 'flutter', 'bin', 'cache', 'pkg', 'baz')
+        })
+      ]).validate();
+    });
+
     test("unlocks an SDK dependency when the version changes", () async {
       await d.appDir({
         "foo": {"sdk": "flutter"}