diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 76b10edf09..21fa2822f9 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -162,7 +162,11 @@ class CreateCommand extends FlutterCommand { generatedCount += _renderTemplate('package', dirPath, templateContext); if (argResults['pub']) - await pubGet(context: PubContext.createPackage, directory: dirPath); + await pubGet( + context: PubContext.createPackage, + directory: dirPath, + offline: true, + ); final String relativePath = fs.path.relative(dirPath); printStatus('Wrote $generatedCount files.'); @@ -180,7 +184,11 @@ class CreateCommand extends FlutterCommand { generatedCount += _renderTemplate('plugin', dirPath, templateContext); if (argResults['pub']) - await pubGet(context: PubContext.createPlugin, directory: dirPath); + await pubGet( + context: PubContext.createPlugin, + directory: dirPath, + offline: true, + ); if (android_sdk.androidSdk != null) gradle.updateLocalProperties(projectPath: dirPath); @@ -218,7 +226,7 @@ class CreateCommand extends FlutterCommand { ); if (argResults['pub']) { - await pubGet(context: PubContext.create, directory: appPath); + await pubGet(context: PubContext.create, directory: appPath, offline: true); injectPlugins(directory: appPath); } diff --git a/packages/flutter_tools/test/commands/create_test.dart b/packages/flutter_tools/test/commands/create_test.dart index 47cc959817..3bcacddca0 100644 --- a/packages/flutter_tools/test/commands/create_test.dart +++ b/packages/flutter_tools/test/commands/create_test.dart @@ -14,6 +14,7 @@ import 'package:flutter_tools/src/commands/create.dart'; import 'package:flutter_tools/src/dart/sdk.dart'; import 'package:flutter_tools/src/version.dart'; import 'package:mockito/mockito.dart'; +import 'package:process/process.dart'; import 'package:test/test.dart'; import '../src/common.dart'; @@ -27,12 +28,14 @@ void main() { Directory temp; Directory projectDir; FlutterVersion mockFlutterVersion; + LoggingProcessManager loggingProcessManager; setUpAll(() { Cache.disableLocking(); }); setUp(() { + loggingProcessManager = new LoggingProcessManager(); temp = fs.systemTempDirectory.createTempSync('flutter_tools'); projectDir = temp.childDirectory('flutter_project'); mockFlutterVersion = new MockFlutterVersion(); @@ -299,6 +302,23 @@ void main() { throwsToolExit(message: '"invalidName" is not a valid Dart package name.'), ); }); + + testUsingContext('invokes pub offline', () async { + Cache.flutterRoot = '../..'; + + final CreateCommand command = new CreateCommand(); + final CommandRunner runner = createTestCommandRunner(command); + + await runner.run(['create', '--pub', projectDir.path]); + final List commands = loggingProcessManager.commands; + expect(commands, contains(matches(r'dart-sdk[\\/]bin[\\/]pub'))); + expect(commands, contains('--offline')); + }, + timeout: allowForCreateFlutterProject, + overrides: { + ProcessManager: () => loggingProcessManager, + }, + ); }); } @@ -359,3 +379,29 @@ Future _analyzeProject(String workingDir, {String target}) async { } class MockFlutterVersion extends Mock implements FlutterVersion {} + +/// A ProcessManager that invokes a real process manager, but keeps +/// the last commands sent to it. +class LoggingProcessManager extends LocalProcessManager { + List commands; + + @override + Future start( + List command, { + String workingDirectory, + Map environment, + bool includeParentEnvironment: true, + bool runInShell: false, + ProcessStartMode mode: ProcessStartMode.NORMAL, + }) { + commands = command; + return super.start( + command, + workingDirectory: workingDirectory, + environment: environment, + includeParentEnvironment: includeParentEnvironment, + runInShell: runInShell, + mode: mode, + ); + } +} \ No newline at end of file