如何在Android Studio,Visual Studio Code上轻松设置Flutter,并开始构建出色的应用程序!

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:02   5798   0

Let’s setup our lab environment for app development using Flutter. We will be using Visual Studio Code and Android studio IDE.

让我们为使用Flutter进行应用程序开发设置实验室环境。 我们将使用Visual Studio Code和Android studio IDE。

那么到底是什么? (So what exactly is flutter?)

Flutter is an open-source UI software development kit created by Google. It is used to develop applications for Android, iOS, Linux, Mac, Windows, Google Fuchsia and the web from a single codebase.

Flutter是Google创建的开源UI软件开发套件。 它用于从单个代码库为Android,iOS,Linux,Mac,Windows,Google Fuchsia和Web开发应用程序。

Flutter consists of two important parts:

Flutter由两个重要部分组成:

  • An SDK (Software Development Kit): A collection of tools that are going to help you develop your applications. This includes tools to compile your code into native machine code (code for iOS and Android).

    SDK(软件开发套件):一系列可帮助您开发应用程序的工具。 这包括将您的代码编译为本机代码(iOS和Android的代码)的工具。
  • A Framework (UI Library based on widgets): A collection of reusable UI elements (buttons, text inputs, sliders, and so on) that you can personalize for your own needs.

    框架(基于窗口小部件的UI库):您可以根据自己的需求进行个性化的可重复使用的UI元素(按钮,文本输入,滑块等)的集合。

To develop with Flutter, you will use a programming language called Dart. The language was created by Google in October 2011, but it has improved a lot over these past years.

要使用Flutter进行开发,您将使用一种称为Dart的编程语言。 该语言是Google于2011年10月创建的,但在过去的几年中,它有了很大的改进。

Dart focuses on front-end development, and you can use it to create mobile and web applications.

Dart专注于前端开发,您可以使用它来创建移动和Web应用程序。

If you know a bit of programming, Dart is a typed object programming language. You can compare Dart’s syntax to JavaScript.

如果您懂一些编程,那么Dart是一种类型化的对象编程语言。 您可以将Dart的语法与JavaScript进行比较。

我可以使用Flutter构建哪些类型的应用程序? (What kinds of apps can I build with Flutter?)

Flutter is optimized for 2D mobile apps that want to run on both Android and iOS. Flutter is also great for interactive apps that you want to run on your web pages or on the desktop. (Note that web support is in beta, and desktop support is in alpha.)

Flutter针对要在Android和iOS上运行的2D移动应用程序进行了优化。 Flutter对于要在网页或桌面上运行的交互式应用程序也非常有用。 (请注意,Web支持处于beta状态,而桌面支持处于alpha状态。)

Apps that need to deliver brand-first designs are particularly well suited for Flutter. However, apps that need to look like stock platform apps can also be built with Flutter.

需要交付品牌第一设计的应用特别适合Flutter。 但是,也可以使用Flutter构建需要看起来像股票平台应用程序的应用程序。

You can build full-featured apps with Flutter, including camera, geolocation, network, storage, 3rd-party SDKs, and more

您可以使用Flutter构建功能全面的应用,包括摄像头,地理位置,网络,存储,第三方SDK等

软件先决条件: (Software Prerequisites:)

Image for post
Prerequisites
先决条件

因此,让我们开始吧! (So let’s get started!)

Firstly, we need to extract the .zip file for Flutter Windows that we’ve downloaded already. As soon as we extract, flutter will be installed. All we need to do is set the path. After extraction, we should get the following files:

首先,我们需要为已经下载的Flutter Windows解压缩.zip文件。 一旦解压缩,就会安装颤振。 我们需要做的就是设置路径。 解压缩后,我们应该获得以下文件:

Image for post
Flutter Windows
颤振窗口
Image for post
This is the program we will use and will have to set it’s path
这是我们将要使用的程序,必须设置其路径
Image for post
New Path added successfully in the Environment Variables
新路径已成功添加到环境变量中

In Command Prompt, if we execute the command “flutter” and the following output comes up, installation of flutter is successful!

在命令提示符中,如果我们执行命令“ flutter”并且出现以下输出, 则表明成功安装了flutter!

Image for post
Installation successful
安装成功

Flutter SDK里面有什么? (What is inside the Flutter SDK?)

  • Heavily optimized, mobile-first 2D rendering engine with excellent support for text

    经过高度优化的,移动优先的2D渲染引擎,具有出色的文本支持
  • Modern react-style framework

    现代React式框架
  • Rich set of widgets implementing Material Design and iOS-style.

    丰富的小部件集,实现了Material Design设计和iOS风格。
  • APIs for unit and integration tests

    用于单元和集成测试的API
  • Interop and plugin APIs to connect to the system and 3rd-party SDKs

    互操作和插件API,用于连接到系统和第三方SDK
  • Headless test runner for running tests on Windows, Linux, and Mac

    无头测试运行程序,用于在Windows,Linux和Mac上运行测试
  • Dart DevTools for testing, debugging, and profiling your app

    Dart DevTools,用于测试,调试和分析应用程序

  • Command-line tools for creating, building, testing, and compiling your apps

    用于创建,构建,测试和编译应用程序的命令行工具

Flutter是否可以与任何编辑器或IDE一起使用? (Does Flutter work with any editors or IDEs?)

Flutter support plugins for Android Studio, IntelliJ IDEA, and VS Code.

Flutter支持Android StudioIntelliJ IDEAVS Code的插件。

Now, initially, if we run the “flutter doctor” command, we will get the following output.

现在,首先,如果我们运行“ flutter doctor”命令,将获得以下输出。

Image for post
flutter doctor
扑医生

因此,让我们开始其余的过程! (So, lets get started with the remaining process!)

Step 1: Installing the Android Studio IDE

步骤1:安装Android Studio IDE

Image for post
Android Studio Setup
Android Studio安装程序

Android Virtual Device

Android虚拟设备

An Android Virtual Device (AVD) is a configuration that defines the characteristics of an Android phone, tablet, Wear OS, Android TV, or Automotive OS device that you want to simulate in the Android Emulator. The AVD Manager is an interface you can launch from Android Studio that helps you create and manage AVDs.

Android虚拟设备(AVD)是一种配置,用于定义要在Android Emulator中模拟的Android手机,平板电脑,Wear OS,Android TV或Automotive OS设备的特征。 AVD Manager是可以从Android Studio启动的界面,可帮助您创建和管理AVD。

So, we need to tick the Android Virtual Device positively.

因此,我们需要积极打勾Android虚拟设备。

Image for post
AVD
视音频

Now, after giving the location for installation, the process is complete.

现在,在提供了安装位置之后,该过程就完成了。

Image for post
Installation Complete
安装完成
Image for post
Select Theme
选择主题
Image for post
Installing the required components (default)
安装所需的组件(默认)
Image for post
Open SDK Manager from Configure
从配置中打开SDK Manager

We need to install the following SDK Tools:

我们需要安装以下SDK工具:

  • Android SDK Build-Tools

    Android SDK构建工具
  • Android Emulator

    Android模拟器
  • Android SDK Platform-Tools

    Android SDK平台工具
  • Android SDK Tools

    Android SDK工具
  • Google USB Driver

    Google USB驱动程序
  • Inter x86 Emulator Accelerator (XAHM installer)

    Inter x86 Emulator Accelerator(XAHM安装程序)
Image for post
SDK Tools
SDK工具

Now, we will have to add a new path for the Android SDK Location.

现在,我们将不得不为Android SDK位置添加新路径。

Image for post
New Environment Variable
新环境变量
Image for post
SDK installed successfully!
SDK安装成功!

We can see here, using the “flutter doctor” command we can see that the Android SDK is installed successfully, but there are some plugins missing, which we will need later.

我们在这里可以看到,使用“ flutter doctor”命令可以看到Android SDK已成功安装,但是缺少一些插件,稍后我们将需要它们。

Image for post
Install Flutter plugin(Dart will automatically be installed).
安装Flutter插件(将自动安装Dart)。

Now, let’s see how to install the AVD Manager

现在,让我们看看如何安装AVD Manager

Image for post
AVD MANAGER
AVD经理
Image for post
Creating a new virtual Device
创建一个新的虚拟设备
Image for post
System Hardware selection
系统硬件选择

One can select any system Hardware and download and install any system image.

您可以选择任何系统硬件,然后下载并安装任何系统映像。

Image for post
System Image
系统映像
Image for post
Naming of Device
设备命名

After naming and verifying, click Finish!

命名并验证后,单击完成!

Image for post
New virtual device successfully created
成功创建新的虚拟设备

If we run the “flutter emulators” command, we can find this output:

如果运行“ flutter emulators”命令,我们可以找到以下输出:

Image for post
Emulator detected
检测到仿真器

Now, if we launch the device, we will get a virtual device having internal RAM, CPU, etc.

现在,如果启动设备,我们将获得一个具有内部RAM,CPU等的虚拟设备。

Image for post
Device launched
设备启动

Now, if we get run “flutter devices” command, we will find that a new device is detected.

现在,如果我们运行“ flutter devices”命令,我们将发现检测到新设备。

Now, let’s call the doctor once more! (“flutter doctor”)

现在,让我们再次致电医生! (“颤抖的医生”)

Image for post
flutter doctor
扑医生

So, finally our lab is ready!

所以,终于我们的实验室准备好了!

让我们运行一个测试应用程序。 (Let’s run a Test Application.)

flutter create test_app
Image for post
test_app
test_app

We can see that it is displaying that our application is in test_app\lib\main.dart.

我们可以看到它显示我们的应用程序在test_app \ lib \ main.dart中。

Image for post
main.dart
main.dart

This is the dart file that has been created. Let’s run this app then!

这是已创建的dart文件。 那我们就运行这个程序吧!

flutter run // from the root folder of the flutter project
Image for post
Security alert
安全警报

We will have to allow access. After a few minutes, our test application will be launched in our device!

我们将不得不允许访问。 几分钟后,我们的测试应用程序将在我们的设备中启动!

Image for post
Application launched Successfully!
应用程序成功启动!

The best thing about this application: It supports Hot Reload (no need to compile after changing the code)

关于此应用程序的最好的事情:它支持热重装 (更改代码后无需编译)

Flutter’s hot reload feature helps you quickly and easily experiment, build UIs, add features, and fix bugs. Hot reload works by injecting updated source code files into the running Dart Virtual Machine (VM). After the VM updates classes with the new versions of fields and functions, the Flutter framework automatically rebuilds the widget tree, allowing you to quickly view the effects of your changes.

Flutter的热重装功能可帮助您快速轻松地进行实验,构建UI,添加功能并修复错误。 通过将更新的源代码文件注入到正在运行的Dart虚拟机(VM)中,热重载可以工作。 VM使用新版本的字段和函数更新类后,Flutter框架会自动重建小部件树,使您可以快速查看更改的效果。

因此,让我们对其进行测试! (So let’s test it!)

Let’s make a change in the dart file.

让我们在dart文件中进行更改。

Image for post
Change
更改

Now, all we need to do is press the “r” key for hot reload!

现在,我们要做的就是按“ r”键进行热装!

Image for post
Application updated
申请已更新

Magic! In just a single click, application updated!

魔法! 只需单击一下,即可更新应用程序!

Now, you guys must be wondering what is the use of Virtual Studio Code, well here it comes! It will provide us with an IDE. For that we need to check a few things, before using it.

现在,你们一定想知道Virtual Studio Code的用途是什么,它来了! 它将为我们提供一个IDE。 为此,我们需要在使用前检查一些事项。

Image for post
msinfo
信息
Image for post
Virtualization
虚拟化

We need to ensure that virtualization is enabled in our device. If not, you will have to enable it from BIOS settings (Hardware Virtualization).

我们需要确保在设备中启用了虚拟化。 如果没有,则必须从BIOS设置(硬件虚拟化)启用它。

Now, our Virtual Studio Code(VSC) is ready for installation.

现在,我们的Virtual Studio Code(VSC)已准备好安装。

Image for post
VSC
VSC
Image for post
Launched!
推出了!

Now, open the folder where the dart file is located.

现在,打开dart文件所在的文件夹。

Image for post
lib folder
lib文件夹
Image for post
Install this flutter extension
安装此flutter扩展
Image for post
dart code
Dart代码
Image for post
Debugging
调试

From here, one can change the code, run the code, run emulator, launch device etc.

从这里,可以更改代码,运行代码,运行仿真器,启动设备等。

Image for post
Final Setup Complete!
最终安装完成!

Here, we can do hot reload by just saving the updated file. (Ctrl+s)

在这里,我们可以通过仅保存更新的文件来进行热重装。 (Ctrl + s)

Image for post
Final flutter doctor
最终扑扑医生

So, a final call to the doctor shows that everything is fit and fine!

因此,最后给医生打电话表明一切都很好。

I hope that everyone will be able to setup this environment very easily and will be able to start building amazing apps with flutter!

我希望每个人都可以非常轻松地设置此环境,并且能够开始动fl地构建出色的应用程序!

For any queries feel free to contact me.

如有任何疑问,请随时联系

Let’s connect in LinkedIn!

让我们在LinkedIn中建立联系

Thank you for reading :”)

谢谢您的阅读 :”)

翻译自: https://medium.com/swlh/how-you-can-easily-setup-your-flutter-lab-environment-and-start-building-amazing-applications-cc50181287d1

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP