Flutter 脚手架Cli安装及项目创建

第一步:安装Cli脚手架

我们通过命令flutter pub global activate get_cli 进行脚手架的全局安装,本文以Mac OS为例。

EternalUMacPro@EternalUniverse ~ % flutter pub global activate get_cli
Resolving dependencies...
+ _fe_analyzer_shared 34.0.0
+ analyzer 3.2.0
+ ansicolor 2.0.1
+ args 2.3.0
+ async 2.8.2
+ charcode 1.3.1
+ cli_dialog 0.5.0
+ cli_util 0.3.5
+ clock 1.1.0
+ collection 1.15.0
+ convert 3.0.1
+ crypto 3.0.1
+ dart_console 1.0.0
+ dart_style 2.2.1
+ ffi 1.1.2 (1.2.0 available)
+ file 6.1.2
+ get_cli 1.7.1
+ glob 2.0.2
+ http 0.13.4
+ http_parser 4.0.0
+ intl 0.17.0
+ matcher 0.12.11
+ meta 1.7.0
+ package_config 2.0.2
+ path 1.8.1
+ process_run 0.12.3+2
+ pub_semver 2.1.0
+ pubspec 2.0.1
+ quiver 3.0.1+1
+ recase 4.0.0
+ source_span 1.8.2
+ stack_trace 1.10.0
+ string_scanner 1.1.0
+ synchronized 3.0.0
+ term_glyph 1.2.0
+ typed_data 1.3.0
+ uri 1.0.0
+ version 2.0.0
+ watcher 1.0.1
+ win32 2.3.6 (2.4.1 available)
+ yaml 3.1.0
Downloading get_cli 1.7.1...
Downloading version 2.0.0...
Downloading recase 4.0.0...
Downloading pubspec 2.0.1...
Downloading cli_dialog 0.5.0...
Downloading ansicolor 2.0.1...
Downloading uri 1.0.0...
Downloading path 1.8.1...
Downloading pub_semver 2.1.0...
Downloading dart_console 1.0.0...
Downloading matcher 0.12.11...
Downloading source_span 1.8.2...
Downloading quiver 3.0.1+1...
Downloading process_run 0.12.3+2...
Downloading dart_style 2.2.1...
Downloading analyzer 3.2.0...
Downloading _fe_analyzer_shared 34.0.0...
Downloading watcher 1.0.1...
Downloading package_config 2.0.2...
Downloading glob 2.0.2...
Downloading cli_util 0.3.5...
Downloading async 2.8.2...
Downloading win32 2.3.6...
Building package executables...
Built get_cli:get.
Installed executables get and getx.
Warning: Pub installs executables into $HOME/Documents/Flutter配置/flutter/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, etc.):

  export PATH="$PATH":"$HOME/Documents/Flutter配置/flutter/.pub-cache/bin"

Activated get_cli 1.7.1.

第二步:设置环境变量

一般Mac的环境变量都是通过根目录的.bash_profile进行环境变量设置。

//终端打开配置文件
EternalUMacPro@EternalUniverse ~ %  open .bash_profile
//在打开的文件中添加路劲<这里看自己路径设置>
#GetX
export PATH="$PATH":"$HOME/Documents/Flutter配置/flutter/.pub-cache/bin"

第三步:使设置的环境变量生效

我们可以通过source 加上路径,对环境变量生效。

EternalUMacPro@EternalUniverse ~ % source "/Users/EternalUniverse/.bash_profile"

第四步:校验是否成功安装

我们通过get命令,看能不能打印如下,如果有,那么恭喜你安装成功了。

EternalUMacPro@EternalUniverse ~ % get

List available commands:

  create:  
    controller:  Generate controller
    page:  Use to generate pages
    project:  Use to generate new project
    provider:  Create a new Provider
    screen:  Generate new screen
    view:  Generate view
  generate:  
    locales:  Generate translation file from json files
    model:  generate Class model from json
  help:  Show this help
  init:  generate the chosen structure on an existing project:
  install:  Use to install a package in your project (dependencies):
  remove:  Use to remove a package in your project (dependencies):
  sort:  Sort imports and format dart files
  update:  To update GET_CLI
  --version:  Shows the current CLI version'

Time: 940 Milliseconds

Cli创建工程

我们可以通过get create project来进行创建工程,

EternalUMacPro@EternalUniverse desktop % get create project
?  (Use arrow keys)
❯ Flutter Project
  Get Server
? what is the name of the project? flutter_artsian
? What is your company's domain?  Example: com.yourcompany  com.Eu
? what language do you want to use on ios? (Use arrow keys)
  Swift
❯ Objective-C
? what language do you want to use on android? (Use arrow keys)
  Kotlin
❯ Java
? Do you want to use null safe? (Use arrow keys)
❯ Yes!
  No
? do you want to use some linter? (Use arrow keys)
❯ no
  Pedantic [Deprecated]
  Effective Dart [Deprecated]
  Dart Recommended

Running `flutter create /Users/EternalU/Desktop/flutter_artsian` …

$ flutter create --no-pub -i objc -a java --org com.Eu /Users/EternalU/Desktop/flutter_artsian
Creating project ....
  test/widget_test.dart (created)
  pubspec.yaml (created)
  README.md (created)
  lib/main.dart (created)
  ios/Runner.xcworkspace/contents.xcworkspacedata (created)
  ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (created)
  ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (created)
  ios/Runner/Info.plist (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png (created)
  ios/Runner/Base.lproj/LaunchScreen.storyboard (created)
  ios/Runner/Base.lproj/Main.storyboard (created)
  ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata (created)
  ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (created)
  ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (created)
  ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (created)
  ios/Flutter/Debug.xcconfig (created)
  ios/Flutter/Release.xcconfig (created)
  ios/Flutter/AppFrameworkInfo.plist (created)
  ios/.gitignore (created)
  flutter_artsian.iml (created)
  .gitignore (created)
  web/favicon.png (created)
  web/index.html (created)
  web/manifest.json (created)
  web/icons/Icon-maskable-512.png (created)
  web/icons/Icon-192.png (created)
  web/icons/Icon-maskable-192.png (created)
  web/icons/Icon-512.png (created)
  .metadata (created)
  ios/Runner/AppDelegate.h (created)
  ios/Runner/main.m (created)
  ios/Runner/AppDelegate.m (created)
  ios/Runner.xcodeproj/project.pbxproj (created)
  android/app/src/profile/AndroidManifest.xml (created)
  android/app/src/main/res/mipmap-mdpi/ic_launcher.png (created)
  android/app/src/main/res/mipmap-hdpi/ic_launcher.png (created)
  android/app/src/main/res/drawable/launch_background.xml (created)
  android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (created)
  android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (created)
  android/app/src/main/res/values-night/styles.xml (created)
  android/app/src/main/res/values/styles.xml (created)
  android/app/src/main/res/drawable-v21/launch_background.xml (created)
  android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (created)
  android/app/src/main/AndroidManifest.xml (created)
  android/app/src/debug/AndroidManifest.xml (created)
  android/gradle/wrapper/gradle-wrapper.properties (created)
  android/gradle.properties (created)
  android/.gitignore (created)
  android/settings.gradle (created)
  android/app/build.gradle (created)
  android/app/src/main/java/com/Eu/flutter_artsian/MainActivity.java (created)
  android/build.gradle (created)
  android/flutter_artsian_android.iml (created)
  analysis_options.yaml (created)
  .idea/runConfigurations/main_dart.xml (created)
  .idea/libraries/Dart_SDK.xml (created)
  .idea/libraries/KotlinJavaRuntime.xml (created)
  .idea/modules.xml (created)
  .idea/workspace.xml (created)
Wrote 82 files.

All done!
In order to run your application, type:

  $ cd .
  $ flutter run

Your application code is in ./lib/main.dart.


Running `flutter pub get` …

$ flutter pub get
Running "flutter pub get" in flutter_artsian...                  1,204ms
$ dart migrate --apply-changes --skip-import-check
Migrating /Users/EternalU/Desktop/flutter_artsian

See https://dart.dev/go/null-safety-migration for a migration guide.

Analyzing project...
All sources appear to be already migrated.  Nothing to do.
✓  File: analysis_options.yaml created successfully at path: analysis_options.yaml
? Which architecture do you want to use? (Use arrow keys)
❯ GetX Pattern (by Kauê)
  CLEAN (by Arktekko)
? Your lib folder is not empty. Are you sure you want to overwrite your application? 
 WARNING: This action is irreversible (Use arrow keys)
❯ Yes!
  No
✓  'Package: get installed!
✓  File: main.dart created successfully at path: lib/main.dart
✓  File: home_controller.dart created successfully at path: lib/app/modules/home/controllers/home_controller.dart
✓  File: home_view.dart created successfully at path: lib/app/modules/home/views/home_view.dart
✓  File: home_binding.dart created successfully at path: lib/app/modules/home/bindings/home_binding.dart
✓  File: app_routes.dart created successfully at path: lib/app/routes/app_routes.dart
✓  File: app_pages.dart created successfully at path: lib/app/routes/app_pages.dart
✓  home route created successfully.
✓  Home page created successfully.
✓  GetX Pattern structure successfully generated.

Running `flutter pub get` …

$ flutter pub get
Running "flutter pub get" in flutter_artsian...                  1,556ms

Time: 46535 Milliseconds

其中的选项自己根据自己的需求修改.在创建过程中遇到一些问题:

//第一个问题
SocketException: OS Error: Operation timed out, errno = 60, address = pub.dev, port = 57422
//处理方法是在hosts文件中添加地址映射
//mac 操作命令: sudo vim /private/etc/hosts   按字母i 进入编辑状态添加映射地址
216.239.32.21 pub.dev
216.239.34.21 pub.dev
216.239.36.21 pub.dev
216.239.38.21 pub.dev
//按 " :wq! "保存退出 
//第二个问题
HandshakeException: Connection terminated during handshake
//请开启科技上网,并开启增强模式.否则就不和你握手了
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,607评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,047评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,496评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,405评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,400评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,479评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,883评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,535评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,743评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,544评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,612评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,309评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,881评论 3 306
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,891评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,136评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,783评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,316评论 2 342