stop.dart 1.32 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 16 17 18
  StopCommand() {
    requiresPubspecYaml();
  }

19
  @override
20
  final String name = 'stop';
21 22

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

25 26
  Device device;

27
  @override
28 29
  Future<Null> validateCommand() async {
    await super.validateCommand();
30 31
    device = await findTargetDevice();
    if (device == null)
32
      throwToolExit(null);
33
  }
34 35

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