install.dart 1.02 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

7 8
import '../application_package.dart';
import '../device.dart';
9
import '../globals.dart';
10
import '../runner/flutter_command.dart';
11

12 13
class InstallCommand extends FlutterCommand {
  final String name = 'install';
14
  final String description = 'Install a Flutter app on an attached device.';
15

16
  bool get requiresDevice => true;
17 18

  @override
19
  Future<int> runInProject() async {
20 21 22 23 24 25 26 27
    await downloadApplicationPackages();

    Device device = deviceForCommand;
    ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);

    printStatus('Installing $package to $device...');

    return installApp(device, package) ? 0 : 2;
28
  }
29
}
30

31 32 33
bool installApp(Device device, ApplicationPackage package) {
  if (package == null)
    return false;
34

35 36
  if (device.isAppInstalled(package))
    return true;
37

38
  return device.installApp(package);
39
}