stop.dart 1.3 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
import '../application_package.dart';
8
import '../base/common.dart';
9
import '../build_info.dart';
10
import '../device.dart';
11
import '../globals.dart';
12
import '../runner/flutter_command.dart';
13

14
class StopCommand extends FlutterCommand {
15
  @override
16
  final String name = 'stop';
17 18

  @override
19 20
  final String description = 'Stop your Flutter app on an attached device.';

21 22
  Device device;

23
  @override
24 25
  Future<Null> verifyThenRunCommand() async {
    commandValidator();
26 27
    device = await findTargetDevice();
    if (device == null)
28
      throwToolExit(null);
29 30
    return super.verifyThenRunCommand();
  }
31 32

  @override
33
  Future<Null> runCommand() async {
34
    final TargetPlatform targetPlatform = await device.targetPlatform;
35
    final ApplicationPackage app = await applicationPackages.getPackageForPlatform(targetPlatform);
36
    if (app == null) {
37
      final String platformName = getNameForTargetPlatform(targetPlatform);
38
      throwToolExit('No Flutter application for $platformName found in the current directory.');
39
    }
40
    printStatus('Stopping apps on ${device.name}.');
41 42
    if (!await device.stopApp(app))
      throwToolExit(null);
43 44
  }
}