[关闭]
@TryLoveCatch 2019-09-19T15:14:20.000000Z 字数 5338 阅读 1525

Flutter之安装

flutter


在 macOS 上安装和配置 Flutter 开发环境

配置镜像

  1. export PUB_HOSTED_URL=https://pub.flutter-io.cn
  2. export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

镜像地址获取

方法一

Using Flutter in China

官网链接,里面有最新的镜像地址

方法二

Flutter中文版
右上角,有一个使用镜像,点击就能看到最新的镜像地址

下载flutter sdk

sdk列表

另外,下载之后,如果需要不同的flutter版本,我们是可以通过git来切换tag的

配置环境变量

  1. open ~/.bash_profile
  2. export FLUTTER_HOME=/Users/lipeng/work/flutter-sdk
  3. export PATH=$PATH:$FLUTTER_HOME/flutter/bin
  4. source ~/.bash_profile
  5. echo $path

检查当前配置环境

  1. flutter doctor

这个命令会检查你当前的配置环境,并在命令行窗口中生成一份报告。

  1. Doctor summary (to see all details, run flutter doctor -v):
  2. [✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.13.6 17G65, locale
  3. zh-Hans-CN)
  4. [!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
  5. ! Some Android licenses not accepted. To resolve this, run: flutter doctor
  6. --android-licenses
  7. [✗] Xcode - develop for iOS and macOS
  8. Xcode installation is incomplete; a full installation is necessary for iOS
  9. development.
  10. Download at: https://developer.apple.com/xcode/download/
  11. Or install Xcode via the App Store.
  12. Once installed, run:
  13. sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
  14. CocoaPods not installed.
  15. CocoaPods is used to retrieve the iOS and macOS platform side's plugin
  16. code that responds to your plugin usage on the Dart side.
  17. Without CocoaPods, plugins will not work on iOS or macOS.
  18. For more info, see https://flutter.dev/platform-plugins
  19. To install:
  20. brew install cocoapods
  21. pod setup
  22. ! Brew can be used to install CocoaPods.
  23. Download brew at https://brew.sh/.
  24. [✗] iOS tools - develop for iOS devices
  25. libimobiledevice and ideviceinstaller are not installed. To install with
  26. Brew, run:
  27. brew update
  28. brew install --HEAD usbmuxd
  29. brew link usbmuxd
  30. brew install --HEAD libimobiledevice
  31. brew install ideviceinstaller
  32. ios-deploy not installed. To install:
  33. brew install ios-deploy
  34. ! Brew can be used to install tools for iOS device development.
  35. Download brew at https://brew.sh/.
  36. [!] Android Studio (version 3.2)
  37. Flutter plugin not installed; this adds Flutter specific functionality.
  38. Dart plugin not installed; this adds Dart specific functionality.
  39. [!] VS Code (version 1.36.0)
  40. Flutter extension not installed; install from
  41. https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
  42. [✓] Connected device (1 available)
  43. ! Doctor found issues in 5 categories.

对照提示,进行修改

安装插件

然后再次执行

  1. flutter doctor

创建应用

导入工程

  1. flutter clean
  2. flutter packages get

常用命令

帮助

flutter支持的命令

  1. flutter -h

执行结果:

  1. Manage your Flutter app development.
  2. Common commands:
  3. flutter create <output directory>
  4. Create a new Flutter project in the specified directory.
  5. flutter run [options]
  6. Run your Flutter application on an attached device or in an emulator.
  7. Usage: flutter <command> [arguments]
  8. Global options:
  9. -h, --help Print this usage information.
  10. -v, --verbose Noisy logging, including all shell commands executed.
  11. If used with --help, shows hidden options.
  12. -d, --device-id Target device id or name (prefixes allowed).
  13. --version Reports the version of this tool.
  14. --suppress-analytics Suppress analytics reporting when this command runs.
  15. --bug-report Captures a bug report file to submit to the Flutter team.
  16. Contains local paths, device identifiers, and log snippets.
  17. --packages Path to your ".packages" file.
  18. (required, since the current directory does not contain a ".packages" file)
  19. Available commands:
  20. analyze Analyze the project's Dart code.
  21. attach Attach to a running application.
  22. bash-completion Output command line shell completion setup scripts.
  23. build Flutter build commands.
  24. channel List or switch flutter channels.
  25. clean Delete the build/ and .dart_tool/ directories.
  26. config Configure Flutter settings.
  27. create Create a new Flutter project.
  28. devices List all connected devices.
  29. doctor Show information about the installed tooling.
  30. drive Runs Flutter Driver tests for the current project.
  31. emulators List, launch and create emulators.
  32. format Format one or more dart files.
  33. help Display help information for flutter.
  34. install Install a Flutter app on an attached device.
  35. logs Show log output for running Flutter apps.
  36. make-host-app-editable Moves host apps from generated directories to non-generated directories so that they can be edited by developers.
  37. precache Populates the Flutter tool's cache of binary artifacts.
  38. pub Commands for managing Flutter packages.
  39. run Run your Flutter app on an attached device.
  40. screenshot Take a screenshot from a connected device.
  41. test Run Flutter unit tests for the current project.
  42. upgrade Upgrade your copy of Flutter.
  43. version List or switch flutter versions.

我们可以看到flutter支持的command:

  1. analyze
  2. build
  3. channel
  4. clean
  5. config
  6. create
  7. devices
  8. doctor
  9. drive
  10. emulators
  11. format
  12. help
  13. install
  14. logs
  15. make-host-app-editable
  16. precache
  17. pub
  18. run
  19. screenshot
  20. test
  21. upgrade
  22. version

具体command的帮助

我们已build为例

  1. flutter build -h

执行结果:

  1. Flutter build commands.
  2. Usage: flutter build <subcommand> [arguments]
  3. -h, --help Print this usage information.
  4. Available subcommands:
  5. aot Build an ahead-of-time compiled snapshot of your app's Dart code.
  6. apk Build an Android APK file from your app.
  7. appbundle Build an Android App Bundle file from your app.
  8. bundle Build the Flutter assets directory from your app.
  9. ios Build an iOS application bundle (Mac OS X host only).
  10. Run "flutter help" to see global options.

查看版本

  1. flutter --version
  2. Flutter 1.7.8+hotfix.4 channel stable https://github.com/flutter/flutter.git
  3. Framework revision 20e59316b8 (5 weeks ago) 2019-07-18 20:04:33 -0700
  4. Engine revision fee001c93f
  5. Tools Dart 2.4.0

遇到的问题

Target of URI doesn't exist 'package:flutter/foundation.dart'

导入项目的时候,遇到了这个问题,那是因为需要需要下载这些包:

  1. flutter packages get
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注