Open mowatermelon opened 6 years ago
在面板中按下F1
键,然后输入doctor
,进入flutter doctor
模式
flutter\bin\
下flutter.bat
文件
#!/usr/bin/env bash
# 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.
# ---------------------------------- NOTE ---------------------------------- #
#
# Please keep the logic in this file consistent with the logic in the
# `flutter.bat` script in the same directory to ensure that Flutter continues
# to work across all platforms!
#
# -------------------------------------------------------------------------- #
set -e
unset CDPATH
function follow_links() {
cd -P "${1%/*}"
local file="$PWD/${1##*/}"
while [[ -h "$file" ]]; do
# On Mac OS, readlink -f doesn't work.
cd -P "${file%/*}"
file="$(readlink "$file")"
cd -P "${file%/*}"
file="$PWD/${file##*/}"
done
echo "$PWD/${file##*/}"
}
# Convert a filesystem path to a format usable by Dart's URI parser.
function path_uri() {
# Reduce multiple leading slashes to a single slash.
echo "$1" | sed -E -e "s,^/+,/,"
}
function _rmlock () {
[ -n "$FLUTTER_UPGRADE_LOCK" ] && rm -f "$FLUTTER_UPGRADE_LOCK"
}
function upgrade_flutter () {
mkdir -p "$FLUTTER_ROOT/bin/cache"
# This function is executed with a redirect that pipes the source of
# this script into file descriptor 3.
#
# To ensure that we don't simultaneously update Dart in multiple
# parallel instances, we try to obtain an exclusive lock on this
# file descriptor (and thus this script's source file) while we are
# updating Dart and compiling the script. To do this, we try to use
# the command line program "flock", which is available on many
# Unix-like platforms, in particular on most Linux distributions.
# You give it a file descriptor, and it locks the corresponding
# file, having inherited the file descriptor from the shell.
#
# Complicating matters, there are two major scenarios where this
# will not work.
#
# The first is if the platform doesn't have "flock", for example on Mac.
# There is not a direct equivalent, so on platforms that don't have flock,
# we fall back to using a lockfile and spinlock with "shlock". This
# doesn't work as well over NFS as it relies on PIDs. Any platform
# without either of these tools has no locking at all. To determine if we
# have "flock" or "shlock" available, we abuse the "hash" shell built-in.
#
# The second complication is NFS. On NFS, to obtain an exclusive
# lock you need a file descriptor that is open for writing, because
# NFS implements exclusive locks by writing, or some such. Thus, we
# ignore errors from flock. We do so by using the '|| true' trick,
# since we are running in a 'set -e' environment wherein all errors
# are fatal, and by redirecting all output to /dev/null, since
# users will typically not care about errors from flock and are
# more likely to be confused by them than helped.
#
# For "flock", the lock is released when the file descriptor goes out of
# scope, i.e. when this function returns. The lock is released via
# a trap when using "shlock".
if hash flock 2>/dev/null; then
flock 3 2>/dev/null || true
elif hash shlock 2>/dev/null; then
FLUTTER_UPGRADE_LOCK="$FLUTTER_ROOT/bin/cache/.upgrade_lock"
while ! shlock -f "$FLUTTER_UPGRADE_LOCK" -p $$ ; do sleep .1 ; done
trap _rmlock EXIT
fi
local revision="$(cd "$FLUTTER_ROOT"; git rev-parse HEAD)"
if [[ ! -f "$SNAPSHOT_PATH" ]] || [[ ! -s "$STAMP_PATH" ]] || [[ "$(cat "$STAMP_PATH")" != "$revision" ]] || [[ "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]]; then
rm -f "$FLUTTER_ROOT/version"
touch "$FLUTTER_ROOT/bin/cache/.dartignore"
"$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
echo Building flutter tool...
if [[ "$TRAVIS" == "true" ]] || [[ "$BOT" == "true" ]] || [[ "$CONTINUOUS_INTEGRATION" == "true" ]] || [[ "$CHROME_HEADLESS" == "1" ]] || [[ "$APPVEYOR" == "true" ]] || [[ "$CI" == "true" ]]; then
PUB_ENVIRONMENT="$PUB_ENVIRONMENT:flutter_bot"
fi
export PUB_ENVIRONMENT="$PUB_ENVIRONMENT:flutter_install"
if [[ -d "$FLUTTER_ROOT/.pub-cache" ]]; then
export PUB_CACHE="${PUB_CACHE:-"$FLUTTER_ROOT/.pub-cache"}"
fi
while : ; do
cd "$FLUTTER_TOOLS_DIR"
"$PUB" upgrade --verbosity=error --no-packages-dir && break
echo Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds...
sleep 5
done
"$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
echo "$revision" > "$STAMP_PATH"
fi
# The exit here is duplicitous since the function is run in a subshell,
# but this serves as documentation that running the function in a
# subshell is required to make sure any lockfile created by shlock
# is cleaned up.
exit $?
}
PROG_NAME="$(path_uri "$(follow_links "$BASH_SOURCE")")"
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
export FLUTTER_ROOT="$(cd "${BIN_DIR}/.." ; pwd -P)"
FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools"
SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot"
STAMP_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.stamp"
SCRIPT_PATH="$FLUTTER_TOOLS_DIR/bin/flutter_tools.dart"
DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk"
DART="$DART_SDK_PATH/bin/dart"
PUB="$DART_SDK_PATH/bin/pub"
# Test if running as superuser – but don't warn if running within Docker
if [[ "$EUID" == "0" ]] && ! [[ -f /.dockerenv ]]; then
echo " Woah! You appear to be trying to run flutter as root."
echo " We strongly recommend running the flutter tool without superuser privileges."
echo " /"
echo "📎"
fi
# Test if Git is available on the Host
if ! hash git 2>/dev/null; then
echo "Error: Unable to find git in your PATH."
exit 1
fi
# Test if the flutter directory is a git clone (otherwise git rev-parse HEAD would fail)
if [[ ! -e "$FLUTTER_ROOT/.git" ]]; then
echo "Error: The Flutter directory is not a clone of the GitHub project."
echo " The flutter tool requires Git in order to operate properly;"
echo " to set up Flutter, run the following command:"
echo " git clone -b beta https://github.com/flutter/flutter.git"
exit 1
fi
# To debug the tool, you can uncomment the following lines to enable checked mode and set an observatory port:
# FLUTTER_TOOL_ARGS="--checked $FLUTTER_TOOL_ARGS"
# FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432"
(upgrade_flutter) 3< "$PROG_NAME"
set +e
"$DART" $FLUTTER_TOOL_ARGS "$SNAPSHOT_PATH" "$@"
# The VM exits with code 253 if the snapshot version is out-of-date.
# If it is, we need to snapshot it again.
EXIT_CODE=$?
if [[ $EXIT_CODE -ne 253 ]]; then
exit $EXIT_CODE
fi
set -e
"$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
"$DART" $FLUTTER_TOOL_ARGS "$SNAPSHOT_PATH" "$@"
flutter create {project-name}
注意新建的文件名中不能是小驼峰,两个单词之间要用下划线链接
flutter create melon_app
cd myapp
官网说这个指令会生成melon_app
文件夹,文件夹下会有一个基础的小项目,核心文件是在lib/main.dart
,可是我测试没有成功,日常摊手.jpg
flutter devices
flutter run
lockfile
文件F1
键之后,再输入flutter
,选择Flutter: New Project
Enter
键,注意输入的文件夹名称不能包含驼峰命名,如果输入名称包含驼峰,输入框会标红提示。这边提示安装dart
, https://www.dartlang.org/install
dart_code_flutter_create.dart
文件,我没有看到其他,我就直接复制,官方中的hello-world
案例代码$ tree # 以树形结构打印目录
卷 文档 的文件夹 PATH 列表
卷序列号为 B0CD-B58D
E:.
├─.vscode
├─android
│ ├─app
│ │ └─src
│ │ └─main
│ │ ├─java
│ │ │ └─io
│ │ │ └─flutter
│ │ │ └─examples
│ │ │ └─hello_world
│ │ └─res
│ │ ├─mipmap-hdpi
│ │ ├─mipmap-mdpi
│ │ ├─mipmap-xhdpi
│ │ ├─mipmap-xxhdpi
│ │ └─mipmap-xxxhdpi
│ └─gradle
│ └─wrapper
├─ios
│ ├─Flutter
│ ├─Runner
│ │ ├─Assets.xcassets
│ │ │ └─AppIcon.appiconset
│ │ └─Base.lproj
│ ├─Runner.xcodeproj
│ │ ├─project.xcworkspace
│ │ └─xcshareddata
│ │ └─xcschemes
│ └─Runner.xcworkspace
├─lib
└─test
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Dart",
"program": "lib/main.dart",
"request": "launch",
"type": "dart"
}
]
}
尝试启动服务,这边直接没有反应,可是安装一直是loading
状态,貌似是SDK
问题。
[flutter] flutter doctor
Waiting for another flutter command to release the startup lock...
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
[X] Android toolchain - develop for Android devices
X Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.io/setup/#android-setup for detailed instructions).
If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.
[X] Android Studio (not installed)
[!] IntelliJ IDEA Ultimate Edition (version 2017.2)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code, 64-bit edition (version 1.26.1)
[!] Connected devices
! No devices available
! Doctor found issues in 5 categories.
exit code 0
Flutter Doctor
[✓] Flutter (Channel dev, v0.3.2, on Mac OS X 10.13.4 17E199, locale en-US)
• Flutter version 0.3.2 at /Users/Wisit/flutter
• Framework revision 44b7e7d3f4 (12 days ago), 2018-04-20 01:02:44 -0700
• Engine revision 09d05a3891
• Dart version 2.0.0-dev.48.0.flutter-fe606f890b
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at /Users/Wisit/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 9.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.3, Build version 9E145
• ios-deploy 1.9.2
• CocoaPods version 1.4.0
[✓] Android Studio (version 3.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 24.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
[✓] IntelliJ IDEA Ultimate Edition (version 2018.1.1)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 23.2.3
• Dart plugin version 181.4445.29
[✓] VS Code (version 1.22.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Dart Code extension version 2.11.2
[✓] Connected devices (1 available)
• iPhone X • 92E4AD04-D69D-4353-BDA3-299CE124A10F • ios • iOS 11.3 (simulator)
• No issues found!
https://github.com/flutter/flutter/wiki/Using-Flutter-in-China
配置前置环境
配置flutter SDK
E:\IDE\flutter
,FLUTTERPATH
变量,避免后期需要多处使用FLUTTERPATH
变量,即%FLUTTERPATH%\bin;
,注意在结尾加上分号flutter -h
,可以明显发现输入指令之后,终端的字体和字号都变化了。E:\IDE\flutter
下对应的flutter_console.bat
运行效果。