• 150403

    文章

  • 892

    评论

  • 13

    友链

  • 最近新加了换肤功能,大家多来逛逛吧~~~~
  • 喜欢这个网站的朋友可以加一下QQ群,我们一起交流技术。

Flutter 开发入门


编者注

由于决定采用FLutter作为未来一段时间的跨平台开发平台。则需要进行测试。顺便写一个简单的gitee的通讯录。如果后续有时间。则写一个更加完善的项目管理软件。

Flutter

IDEA使用Flutter

Mac版本的IDEA,找到Prefermences->pulgin,下载Flutter的支持。这里会提示,是否要安装Dart。选择是。下载后重启IDEA。

下载SDK

当使用IDEA在创建项目的过程,会被下载Flutter的SDK。则下载到指定目录。这里个人习惯是下载的build文件内。
当下载完毕后,碰到IDEA提示如下信息

The Flutter SDK installation is incomplete; please see: https://flutter.io/docs/get-started/install.

这里建议访问中国文档站,速度会快很多起步:安装Flutter

环境配置

首先,需要到执行flutter的更新

./~/build/flutter/bin/flutter doctor

这个时候,能够感受到中国和国际网络连接的深深恶意。

./flutter doctor
Downloading Dart SDK from Flutter engine 9e6314d348f9b5521e3c66856324d7a9c4a928c9...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
 11  259M   11 30.7M    0     0  24789      0  3:03:17  0:21:41  2:41:36     0
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

Failed to retrieve the Dart SDK from: https://storage.googleapis.com/flutter_infra/flutter/9e6314d348f9b5521e3c66856324d7a9c4a928c9/dart-sdk-darwin-x64.zip
If you're located in China, please see this page:
  https://flutter.dev/community/china

下载中断,要我去看中国的配置

编写自动化配置

echo "China flutter config..."
export PUB_HOSTED_URL="https://pub.flutter-io.cn"
echo "[PUB_HOSTED_URL]:$PUB_HOSTED_URL"
sleep 1 | echo

export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
echo "[FLUTTER_STORAGE_BASE_URL]:$FLUTTER_STORAGE_BASE_URL"
sleep 1 | echo

echo "goto [build]"
cd ~
mkdir build
cd build
echo "[current directory:]" | pwd
sleep 1 | echo

echo "flutter.git downloading..."
git clone -b dev https://github.com/flutter/flutter.git
sleep 1 | echo

export PATH="~/build/flutter/bin:$PATH"
echo "[PATH]:$PATH"
sleep 1 | echo

flutter doctor

运行结果

zhanpeng@192 gitee-client % ./flutter-china-install.sh 
China flutter config...
[PUB_HOSTED_URL]:https://pub.flutter-io.cn

[FLUTTER_STORAGE_BASE_URL]:https://storage.flutter-io.cn

goto [build]
mkdir: build: File exists
/Users/zhanpeng/build

flutter.git downloading...
fatal: destination path 'flutter' already exists and is not an empty directory.

[PATH]:~/build/flutter/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands

Downloading Dart SDK from Flutter engine 9e6314d348f9b5521e3c66856324d7a9c4a928c9...
** Resuming transfer from byte position 4284416
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  256M  100  256M    0     0  11.6M      0  0:00:22  0:00:22 --:--:-- 12.0M
Building flutter tool...

  ╔════════════════════════════════════════════════════════════════════════════╗
  ║                 Welcome to Flutter! - https://flutter.dev                  ║
  ║                                                                            ║
  ║ The Flutter tool anonymously reports feature usage statistics and crash    ║
  ║ reports to Google in order to help Google contribute improvements to       ║
  ║ Flutter over time.                                                         ║
  ║                                                                            ║
  ║ Read about data we send with crash reports:                                ║
  ║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting        ║
  ║                                                                            ║
  ║ See Google's privacy policy:                                               ║
  ║ https://www.google.com/intl/en/policies/privacy/                           ║
  ║                                                                            ║
  ║ Use "flutter config --no-analytics" to disable analytics and crash         ║
  ║ reporting.                                                                 ║
  ╚════════════════════════════════════════════════════════════════════════════╝


Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Downloading Material fonts...                                       0.7s
Downloading Gradle Wrapper...                                       0.1s
Downloading android-arm-profile/darwin-x64 tools...                 0.6s
Downloading android-arm-release/darwin-x64 tools...                 0.5s
Downloading android-arm64-profile/darwin-x64 tools...               0.6s
Downloading android-arm64-release/darwin-x64 tools...               0.5s
Downloading package sky_engine...                                   0.4s
Downloading common tools...                                         1.8s
Downloading common tools...                                         1.6s
Downloading darwin-x64 tools...                                     3.8s
Downloading libimobiledevice...                                     0.2s
Downloading usbmuxd...                                              0.1s
Downloading libplist...                                             0.1s
Downloading openssl...                                              0.3s
Downloading ideviceinstaller...                                     0.1s
Downloading ios-deploy...                                           0.1s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v1.10.7, on Mac OS X 10.15.1 19B88, locale en)
[✗] Android toolchain - develop for Android devices
    ✗ 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.dev/setup/#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
      You may also want to add it to your PATH environment variable.

[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    ✗ CocoaPods not installed.
        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 install:
        sudo gem install cocoapods
[!] Android Studio (not installed)
[!] IntelliJ IDEA Ultimate Edition (version 2019.2.4)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
    ! No devices available

! Doctor found issues in 5 categories.

注意:mac的命令行会让export的配置内容,在关闭时失效。如果希望减少脚本编写。可以完全把路径配置到系统当中。
这些提示的后续问题,需要根据你开发的App的平台进行决定。

尝试运行

如果正确运行完毕,则IDEA能够正确创建项目了。但是不能够正常运行,这里主要原因Connected device - ! No devices available
编者之前不想下载xcode,至此还是老实的去下载xcode,方便使用IOS simulator
当笔者通过App Store下载好Xcode后,点击Open IOS simulator,竟然报错

Error Opening Simulator
LSOPenURLsWithRole() failed for the application
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app with eror -10810

后面发现,由于没有运行xcode,导致xcode没有进行初始化运行,和license授权导致这个异常的发生。点击之后通过

重新运行

这次点击Open IOS Simuluator 能够看到对应设备,这里是iphone 11 pro max。点击运行,会发现下载一些内容。

Downloading ios tools...                                           11.3s
Downloading ios-profile tools...                                   11.1s
Downloading ios-release tools...                                   38.1s
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Running Xcode build...
Xcode build done.                                           76.8s

最后,能够在模拟器当中看到App的运行。


695856371Web网页设计师②群 | 喜欢本站的朋友可以收藏本站,或者加入我们大家一起来交流技术!

0条评论

Loading...


发表评论

电子邮件地址不会被公开。 必填项已用*标注

自定义皮肤 主体内容背景
打开支付宝扫码付款购买视频教程
遇到问题联系客服QQ:419400980
注册梁钟霖个人博客