Skip to content
Snippets Groups Projects
flutter.dart 1.18 KiB
Newer Older
// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. 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:io';

import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';

import 'exceptions.dart';
import 'io.dart';

/// Whether the Flutter SDK is available.
final bool isAvailable = Platform.environment.containsKey("FLUTTER_ROOT");

/// The path to the root directory of the Flutter SDK.
final String rootDirectory = Platform.environment["FLUTTER_ROOT"];

/// The Flutter SDK's version number, or `null` if the Flutter SDK is
/// unavailable.
final Version version = () {
  if (!isAvailable) return null;

  return new Version.parse(
      readTextFile(p.join(rootDirectory, "version")).trim());
}();
Natalie Weizenbaum's avatar
Natalie Weizenbaum committed

/// Returns the path to the package [name] within Flutter.
String packagePath(String name) {
    throw new ApplicationException(
        'Flutter is not available. If this is a Flutter project, make sure to '
Jacob MacDonald's avatar
Jacob MacDonald committed
        'always run\n'
        'pub through the "flutter" executable.');
  }
Natalie Weizenbaum's avatar
Natalie Weizenbaum committed

  return p.join(rootDirectory, 'packages', name);
}