install.dart 1.05 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
class InstallCommand extends FlutterCommand {
13
  @override
14
  final String name = 'install';
15 16

  @override
17
  final String description = 'Install a Flutter app on an attached device.';
18

19
  @override
20
  bool get requiresDevice => true;
21 22

  @override
23
  Future<int> runInProject() async {
24 25 26 27 28 29 30 31
    await downloadApplicationPackages();

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

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

    return installApp(device, package) ? 0 : 2;
32
  }
33
}
34

35 36 37
bool installApp(Device device, ApplicationPackage package) {
  if (package == null)
    return false;
38

39 40
  if (device.isAppInstalled(package))
    return true;
41

42
  return device.installApp(package);
43
}