Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter: Create and run a simple Flutter app #204

Open
2 tasks done
Tracked by #205 ...
hhstore opened this issue Aug 15, 2020 · 9 comments
Open
2 tasks done
Tracked by #205 ...

Flutter: Create and run a simple Flutter app #204

hhstore opened this issue Aug 15, 2020 · 9 comments
Labels

Comments

@hhstore
Copy link
Owner

hhstore commented Aug 15, 2020

related:

@hhstore
Copy link
Owner Author

hhstore commented Aug 15, 2020

flutter 开发环境搭建:

  • 参考flutter 官方教程配置, 没有坑.
  • 主要流程:
    • 安装 flutter SDK.
    • 设置 flutter 环境变量.
    • 安装/配置 xcode + iOS 模拟器.
    • 安装/配置 Android studio + Android NDK.
    • 运行示例 demo app 到 iOS 模拟器.
  • vscode 配置 + 运行 Debug 调试模式.

vscode 配置:

Android Studio 配置:

flutter 高效输入插件:

ref:

@hhstore
Copy link
Owner Author

hhstore commented Aug 15, 2020

1. 下载+安装 flutter SDK:

1.0 手动安装 flutter:

  • 可以直接跳到 1.1, 使用 FVM 安装管理 flutter 版本.

# 下载:
wget -P ~/Downloads https://storage.flutter-io.cn/flutter_infra/releases/stable/macos/flutter_macos_1.20.0-stable.zip

# 创建 sdk 根目录:
mkdir ~/sdk

# 解压到 sdk 目录: 
cd ~/sdk
unzip ~/Downloads/flutter_macos_1.20.0-stable.zip




# 设置flutter sdk 环境变量: 
# export PATH="$PATH":"$HOME/sdk/flutter/bin/cache/dart-sdk/bin"


# for dart: 
export PATH="$PATH:/usr/lib/dart/bin"

# for dart pub:
export PATH="$PATH":"$HOME/.pub-cache/bin"

# fvm:
export FVM_HOME="$HOME/.fvm"

# use fvm: fluter + dart + pub
export PATH="$PATH":"$HOME/.fvm/default/bin":"$HOME/.fvm/default/bin/cache/dart-sdk/bin"


# 
# android 环境变量: Android Studio安装的sdk,则其路径可能不同,请自行确定。
# 
export ANDROID_HOME=~/sdk/android
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator




# 查看安装版本号:
-> % flutter --version
Flutter 1.20.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 840c9205b3 (10 days ago) • 2020-08-04 20:55:12 -0700
Engine • revision c8e3b94853
Tools • Dart 2.9.0


# 验证: 
flutter doctor

1.1 安装 fvm:

brew tap leoafarias/fvm
brew install fvm
  • 不建议使用 pub 安装:
dart pub global activate fvm
  • .gitignore 添加忽略:
.fvm/flutter_sdk
  • 查看 fvm 配置:
fvm config

1.1 设置 flutter 环境变量:

image

  • 环境检测: 当前属于正常.

image

2. 模拟器安装+启动:

2.1 配置 iOS 模拟器:

2.2 配置 Android 模拟器:

image

  • 选择手机型号:

image

  • 下载 Android 版本:

image

  • 选择:

image

  • 同意, next:

image

  • 下载 1GB 大小的包.

image

image

3. 编辑器设置: vscode

4. 运行示例 app:


# mac 下, 先启动一个 iOS 模拟器:
open -a Simulator

# 创建示例项目: 
flutter create my_app

cd my_app

# 启动: 
flutter run

  • 如图: 启动的模拟器效果

image

  • 至此, 说明 flutter 的开发环境是正常的.
  • 因为在 mac 下做开发, 有 XCode + iOS模拟器, 就足够.
  • 暂时不需要搭建 Android 的环境, 就不安装 Android Studio 和 Android 的 NDK 了.

@hhstore
Copy link
Owner Author

hhstore commented Aug 15, 2020

关于 Xcode + iOS 模拟器:

@hhstore
Copy link
Owner Author

hhstore commented Aug 15, 2020

使用 vscode 调试 flutter:

image

  • F5, 选择 flutter, 启动 debug 模式. 如下图, 模拟器效果.

image

image

  • 可以浏览器打开 devTool, 这个功能很强大.

image

  • 浏览器查看: 方便做进一步的性能分析.

image

关于 flutter 的开发者工具套件:

@hhstore
Copy link
Owner Author

hhstore commented Aug 15, 2020

xxxxxx:

xxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxx

@hhstore hhstore added the vscode Visual Studio Code label Aug 15, 2020
@hhstore hhstore mentioned this issue Aug 15, 2020
2 tasks
@hhstore
Copy link
Owner Author

hhstore commented Aug 15, 2020

@hhstore
Copy link
Owner Author

hhstore commented Aug 16, 2020

Android Studio 配置:

下载:

安装:

image

  • IDE 安装步骤, 需要从 google 下载 Android 模拟器. (需要科学上网).

  • Android SDK 安装成功, 点击finish.

image

  • 手动取消, 后续再单独安装.

image

配置:

安装 flutter 相关插件:

  • flutter:

image

  • dart :
    image

IDE 配置:

  • 配置 flutter SDK 路径:

image

  • 配置好 flutter 的 SDK Path, 然后 dartSDK Path 会自动检测到.

image

配置项优化:

IDE 智能提示, 禁用输入大小写 匹配.

高效的 flutter snippets 输入:

image

  • 快捷输入关键词列表:

image

  • 具体演示效果, 参看该文档 gif 演示.

image

@hhstore
Copy link
Owner Author

hhstore commented Aug 17, 2020

1

@hhstore hhstore mentioned this issue Aug 18, 2020
11 tasks
@hhstore
Copy link
Owner Author

hhstore commented Sep 28, 2020

android 模拟器环境问题修复:

  • flutter doctor -v

image

  • 修复: flutter doctor --android-licenses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant