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/[email protected] (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/[email protected] (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/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (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
//请开启科技上网,并开启增强模式.否则就不和你握手了

你可能感兴趣的:(Flutter 脚手架Cli安装及项目创建)