Flutter环境配置、创建第一个Flutter App
Flutter包已下载解压缩,接下来更新环境变量。 (Mac OS系统)
cd $HOME
vim ~/.bash_profile
在打开的页面添加上下面代码
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cnexport
PATH=/Users/xxx/Documents/flutter/bin:$PATH //Flutter SDK的目录
配置完成后,再调用下面命令使之生效。下次无论在哪打开shell都可以使用flutter命令;
source ~/.bash_profile
注意:现配置完后每次重新打开终端都要重新source ~/.bash_profile才可以正常使用flutter命令
这个时候就可以使用flutter命令了,现在打开终端,运行:
flutter -h
正常的话就会出来flutter的命令帮助简介。
2、通过运行flutter/bin命令验证目录是否在已经在PATH中:
echo $PATH
/Users/xxx/Documents/flutter/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/hst/.rvm/bin:/Users/hst/.rvm/bin
有包含flutter/bin说明环境变量设置成功!
接下来创建第一个Flutter App
cd到要创建到目录下,
flutter create myapp
Creating project myapp...
myapp/ios/Runner.xcworkspace/contents.xcworkspacedata (created)
myapp/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (created)
myapp/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
(created)
myapp/ios/Runner/Info.plist (created)
myapp/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
(created)
myapp/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
(created)
myapp/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md (created)
myapp/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json (created)
myapp/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
(created)
myapp/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
(created)
myapp/ios/Runner/Base.lproj/LaunchScreen.storyboard (created)
myapp/ios/Runner/Base.lproj/Main.storyboard (created)
myapp/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
(created)
myapp/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks
.plist (created)
myapp/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.
xcsettings (created)
myapp/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (created)
myapp/ios/Flutter/Debug.xcconfig (created)
myapp/ios/Flutter/Release.xcconfig (created)
myapp/ios/Flutter/AppFrameworkInfo.plist (created)
myapp/ios/.gitignore (created)
myapp/test/widget_test.dart (created)
myapp/myapp.iml (created)
myapp/.gitignore (created)
myapp/web/favicon.png (created)
myapp/web/index.html (created)
myapp/web/manifest.json (created)
myapp/web/icons/Icon-192.png (created)
myapp/web/icons/Icon-512.png (created)
myapp/.metadata (created)
myapp/android/app/src/profile/AndroidManifest.xml (created)
myapp/android/app/src/main/res/mipmap-mdpi/ic_launcher.png (created)
myapp/android/app/src/main/res/mipmap-hdpi/ic_launcher.png (created)
myapp/android/app/src/main/res/drawable/launch_background.xml (created)
myapp/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (created)
myapp/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (created)
myapp/android/app/src/main/res/values-night/styles.xml (created)
myapp/android/app/src/main/res/values/styles.xml (created)
myapp/android/app/src/main/res/drawable-v21/launch_background.xml (created)
myapp/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (created)
myapp/android/app/src/main/AndroidManifest.xml (created)
myapp/android/app/src/debug/AndroidManifest.xml (created)
myapp/android/gradle/wrapper/gradle-wrapper.properties (created)
myapp/android/gradle.properties (created)
myapp/android/.gitignore (created)
myapp/android/settings.gradle (created)
myapp/android/app/build.gradle (created)
myapp/android/app/src/main/kotlin/com/example/myapp/MainActivity.kt (created)
myapp/android/build.gradle (created)
myapp/android/myapp_android.iml (created)
myapp/pubspec.yaml (created)
myapp/README.md (created)
myapp/ios/Runner/Runner-Bridging-Header.h (created)
myapp/ios/Runner/AppDelegate.swift (created)
myapp/ios/Runner.xcodeproj/project.pbxproj (created)
myapp/lib/main.dart (created)
myapp/.idea/runConfigurations/main_dart.xml (created)
myapp/.idea/libraries/Dart_SDK.xml (created)
myapp/.idea/libraries/KotlinJavaRuntime.xml (created)
myapp/.idea/modules.xml (created)
myapp/.idea/workspace.xml (created)
Running "flutter pub get" in myapp... 2,718ms
Wrote 78 files.
All done!
In order to run your application, type:
$ cd myapp
$ flutter run
To enable null safety, type:
$ cd myapp
$ dart migrate --apply-changes
Your application code is in myapp/lib/main.dart.
看到底下这几行,说明已经成功创建Flutter App了。
打卡项目底下的ios/Runner.xcworkspace,运行到模拟器,可以看到如下效果了:
1 点击“+”按钮之后Android Studio下载:https://www.runoob.com/android/android-studio-install.html
参考文章:https://www.jianshu.com/p/796bb7811797