blob: 9ba839cdc239fec3b593953ba383f9346315d234 [file] [log] [blame]
// Copyright (c) 2018, 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 '../io.dart';
import '../sdk.dart';
class FlutterSdk extends Sdk {
String get name => 'Flutter';
bool get isAvailable => _isAvailable;
Version get firstPubVersion => Version.parse('1.19.0');
static final bool _isAvailable =
static final String _rootDirectory = Platform.environment['FLUTTER_ROOT'];
String get installMessage =>
'Flutter users should run `flutter pub get` instead of `pub get`.';
Version get version {
if (!_isAvailable) return null;
_version ??=
Version.parse(readTextFile(p.join(_rootDirectory, 'version')).trim());
return _version;
Version _version;
String packagePath(String name) {
if (!isAvailable) return null;
// Flutter packages exist in both `$flutter/packages` and
// `$flutter/bin/cache/pkg`. This checks both locations in order. If [name]
// exists in neither place, it returns the `$flutter/packages` location
// which is more human-readable for error messages.
var packagePath = p.join(_rootDirectory, 'packages', name);
if (dirExists(packagePath)) return packagePath;
var cachePath = p.join(_rootDirectory, 'bin', 'cache', 'pkg', name);
if (dirExists(cachePath)) return cachePath;
return null;