美文网首页
Flutter 项目创建

Flutter 项目创建

作者: 蓝白七七 | 来源:发表于2021-11-23 16:09 被阅读0次

https://blog.csdn.net/u010505059/article/details/99695716

SDK 下载位置
Mac ~ % cd /Users/mac/Library/FlutterSDK 

Mac FlutterSDK % git clone -b master https://github.com/flutter/flutter.git
Cloning into 'flutter'...
remote: Enumerating objects: 325720, done.
remote: Counting objects: 100% (141/141), done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 325720 (delta 67), reused 115 (delta 57), pack-reused 325579
Receiving objects: 100% (325720/325720), 155.00 MiB | 1.08 MiB/s, done.
Resolving deltas: 100% (252504/252504), done.
Updating files: 100% (5443/5443), done.


Mac FlutterSDK % ./flutter/bin/flutter --version
Downloading Dart SDK from Flutter engine ed25e8f01efe6e778cdc65a1858ba3c5ce629786...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  218M  100  218M    0     0   998k      0  0:03:44  0:03:44 --:--:-- 6703k
Building flutter tool...
Flutter 2.4.0-1.0.pre.181 • channel master • https://github.com/flutter/flutter.git
Framework • revision cc00e7e6bc (2 hours ago) • 2021-07-11 18:21:02 -0400
Engine • revision ed25e8f01e
Tools • Dart 2.14.0 (build 2.14.0-301.0.dev)

  ╔════════════════════════════════════════════════════════════════════════════╗
  ║                 Welcome to Flutter! - https://flutter.dev                  ║
  ║                                                                            ║
  ║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
  ║ statistics and basic crash reports. This data is used to help improve      ║
  ║ Flutter tools over time.                                                   ║
  ║                                                                            ║
  ║ Flutter tool analytics are not sent on the very first run. To disable      ║
  ║ reporting, type 'flutter config --no-analytics'. To display the current    ║
  ║ setting, type 'flutter config'. If you opt out of analytics, an opt-out    ║
  ║ event will be sent, and then no further information will be sent by the    ║
  ║ Flutter tool.                                                              ║
  ║                                                                            ║
  ║ By downloading the Flutter SDK, you agree to the Google Terms of Service.  ║
  ║ Note: The Google Privacy Policy describes how data is handled in this      ║
  ║ service.                                                                   ║
  ║                                                                            ║
  ║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and  ║
  ║ crash reports to Google.                                                   ║
  ║                                                                            ║
  ║ Read about data we send with crash reports:                                ║
  ║ https://flutter.dev/docs/reference/crash-reporting                         ║
  ║                                                                            ║
  ║ See Google's privacy policy:                                               ║
  ║ https://policies.google.com/privacy                                        ║
  ╚════════════════════════════════════════════════════════════════════════════╝

配置环境变量 :
压缩包下载好以后, 找个位置进行解压, 这个位置很重要, 因为下面配置环境变量的时候要用到
命令行 SDK 下载的位置

/Users/shiran/Desktop/Flutter/Flatter-Repository/FlutterSDK/flutter
  • 打开终端工具 使用 vim 进行配置环境变量 命令如下 :
$ vim ~/.bash_profile
  • 在文件中写入下列代码 :
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
  • 执行命令立即生效:
 source .bash_profile
解说
export PUB_HOSTED_URL=https://pub.flutter-io.cn # 国内用户需要设置
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn # 国内用户需要设置
export PATH=/Users/用户名/development/flutter/bin:$PATH   # flutter的sdk路径

vi 编辑时出现 E325:ATTENTION 错误
这是由于在编辑该文件的时候异常退出了,因为 vim 在编辑文件时会创建一个交换文件 swap file 以保证文件的安全性。

  • 解决办法:直接 按 D
    为了去掉这个警告,我们需要删除这个 swp 文件:rm -f .config.swp

2、添加 flutter 相关工具到 path 中:
这行命令你要根据你把压缩包解压的位置来进行编写,写的是你的路径:

 目前 命令行集成的使用 SDK 的方式 是:
 export PATH="/Users/shiran/Desktop/Flutter/Flatter-Repository/FlutterSDK/flutter/bin:$PATH"
   
 示例:
 export PATH="/Applications/Flutter/flutter/bin:$PATH"

3、配置文件完成后,使用 source 命令重新加载一下,具体命令如下:

 source ~/.bash_profile

4、使用命令检查是否安装成功,具体命令如下:

flutter --version

 mac@xiaoxinxindeMac ~ % cd /Users/mac/Library/FlutterSDK
 shiran@Mac FlutterSDK % source ~/.bash_profile
 shiran@Mac FlutterSDK % flutter --version
 Flutter 2.4.0-1.0.pre.145 • channel master • https://github.com/flutter/flutter.git
 Framework • revision 48ac40904a (49 minutes ago) • 2021-07-08 23:48:14 -0700
 Engine • revision 53d1a53ac3
 Tools • Dart 2.14.0 (build 2.14.0-293.0.dev)
 shiran@Mac FlutterSDK %

5、运行以下命令查看是否需要安装其它依赖项来完成安装

 $ flutter doctor

该命令检查您的环境并在终端窗口中显示报告。
Dart SDK 已经在捆绑在 Flutter 里了,没有必要单独安装 Dart。 仔细检查命令行输出以获取可能需要安装的其他软件或进一步需要执行的任务(以粗体显示)

shiran@Mac FlutterSDK % flutter doctor
Downloading Material fonts...                                       3.1s
Downloading Gradle Wrapper...                                      496ms
Downloading package sky_engine...                                  696ms
Downloading flutter_patched_sdk tools...                           742ms
Downloading flutter_patched_sdk_product tools...                 1,565ms
Downloading darwin-x64 tools...                                    15.5s
Downloading libimobiledevice...                                    339ms
Downloading usbmuxd...                                             283ms
Downloading libplist...                                            485ms
Downloading openssl...                                           1,053ms
Downloading ios-deploy...                                          325ms
Downloading darwin-x64/font-subset tools...                        877ms
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 2.4.0-1.0.pre.145, on macOS 11.4 20F71 darwin-x64, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[!] Xcode - develop for iOS and macOS
    ! CocoaPods 1.9.3 out of date (1.10.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin
        usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.5)
[✓] IntelliJ IDEA Community Edition (version 2020.2.3)
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.
shiran@Mac FlutterSDK %

// 提示的是 安卓系统没有安装 
遇到的问题
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 2.4.0-1.0.pre.181, on Mac OS X 10.15.7 19H1217 darwin-x64, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[!] Xcode - develop for iOS and macOS
    ! CocoaPods 1.9.3 out of date (1.10.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your
        plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[!] IntelliJ IDEA Community Edition (version 2016.3.5)
    ✗ This install is older than the minimum recommended version of 2017.1.0.
[✓] Connected device (1 available)

! Doctor found issues in 3 categories.

相关文章

网友评论

      本文标题:Flutter 项目创建

      本文链接:https://www.haomeiwen.com/subject/gqcrpltx.html