Flutter Introduction

Flutter Introduction

  • Flutter is an open-source mobile application development framework launched by Google and has cross-platform, high-fidelity and high-performance features. The Dart language allows developers to create apps that run on both iOS and Android. Flutter provides a rich set of components and interfaces that developers can quickly add native extensions to the Flutter. Also, Flutter uses the Native engine to render views, which undoubtedly provides a good experience for users.

  • The Flutter Widget is built with a modern responsive framework, inspired by React. The central idea is to build your UI with widgets. Widgets describe what their views should look like given their current configuration and state. As the widget's state changes, the widget rebuilds the UI, and Flutter compares the changes to determine the minimum change from one state to the next in the underlying rendering tree.

The advantage of Flutter

  • Cross-platform paint engine
    Flutter differs from most other frameworks for building mobile applications in that it uses neither WebView nor native controls of the operating system. Instead, Flutter uses its own high-performance rendering engine to draw widgets. This not only ensures the consistency of the UI on Android and iOS, but also avoids the limitations and high maintenance costs of relying on native controls.

  • A high performance
    The Flutter's performance depends on two things. First, The Flutter APP was developed by using Dart language.Dart is basically the same speed as JavaScript in JIT(Just-in-time) mode. But Dart supports AOT(Ahead of time), and when run in AOT mode, Faster than JavaScript. Second, Flutter uses its own rendering engine to draw the UI, so there is no need to communicate with Native during the layout process.

  • Compatibility
    Flutter is a single language and a single framework independent of the platform, so it does not need to do platform adaptation as often as RN.

  • Hot reload
    Which can greatly improve the development efficiency.

  • Rich widget libraries
    A large number of widget libraries have been implemented officially, and a large number of open source widgets have been unofficially contributed.

  • Development tool support
    Android Studio, IntelliJ, and VSCode all provide development plug-ins with a high degree of completion, as well as support for autoprompt, breakpoint prompt, stack information view and so on.

The disadvantage of Flutter

  • There are still many problems with the current version of Flutter.

Build the Flutter development environment on Windows

System requirements

To install and run Flutter, your development environment must meet these minimum requirements:

  • Operating Systems: Windows 7 SP1 or later (64-bit)
  • Disk Space: 400 MB (does not include disk space for IDE/tools).
  • Tools: Flutter depends on these tools being available in your environment.
    • Windows PowerShell 5.0 or newer (this is pre-installed with Windows 10).
    • Git for Windows 2.x, with the Use Git from the Windows Command Prompt option.
      If Git for Windows is already installed, make sure you can run git commands from the command prompt or PowerShell.

Install Flutter

Since sometimes access to Flutter in China may be restricted, Flutter has officially set up a temporary image for Chinese developers. you can add the following environment variables to the user environment variables:

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

Get the Flutter SDK

  1. Download the following installation bundle to get the latest stable release of the Flutter SDK:

https://flutter.dev/docs/development/tools/sdk/releases

  1. Extract the zip file and place the contained flutter in the desired installation location for the Flutter SDK (for example, C:\src\flutter; do not install Flutter in a directory like C:\Program Files\ that requires elevated privileges).

Update your path

If you wish to run Flutter commands in the regular Windows console, take these steps to add Flutter to the PATH environment variable:

  • From the Start search bar, enter ‘env’ and select Edit environment variables for your account.
  • Under User variables check if there is an entry called Path:
    • If the entry exists, append the full path to flutter\bin using ; as a separator from existing values.
    • If the entry doesn’t exist, create a new user variable named Path with the full path to flutter\bin as its value.

Note that you have to close and reopen any existing console windows for these changes to take effect.

Run flutter doctor

From a console window that has the Flutter directory in the path (see above), run the following command to see if there are any platform dependencies you need to complete the setup:

C:\src\flutter>flutter doctor

This command checks your environment and displays a report of the status of your Flutter installation. Check the output carefully for other software you might need to install or further tasks to perform (shown in bold text).

Install the Flutter and Dart plugins

To install these:

  1. Start Android Studio.
  2. Open plugin preferences (Configure > Plugins as of v3.6.3.0 or later).
  3. Select the Flutter plugin and click Install.
  4. Click Yes when prompted to install the Dart plugin.
  5. Click Restart when prompted.

[Build the Flutter development environment on Mac]

(https://flutter.dev/docs/get-started/install/macos)

Hot reload

Flutter’s hot reload feature helps you quickly and easily experiment, build UIs, add features, and fix bugs.

To hot reload a Flutter app:

  • Run the app from a supported Flutter editor or a terminal window. Either a physical or virtual device can be the target. Only Flutter apps in debug mode can be hot reloaded.
  • Modify one of the Dart files in your project. Most types of code changes can be hot reloaded; for a list of changes that require a hot restart, see Limitations.
  • If you’re working in an IDE/editor that supports Flutter’s IDE tools, select Save All (cmd-s/ctrl-s), or click the Hot Reload button on the toolbar:

Flutter module supports hot reload

run:

flutter attach

Waiting for a connection from Flutter on SM N9600...
Syncing files to device SM N9600...
 6,061ms (!)

 To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".
An Observatory debugger and profiler on SM N9600 is available at: http://127.0.0.1:61382/dcDqRpWTVVI=/
For a more detailed help message, press "h". To detach, press "d"; to quit, press "q".

The above indicates that the connection is successful, as long as there is a change, You can see the changes by clicking on the keyboard R or r.
If you are waiting after running the command, try to kill the application process and restart it. Go to the relevant Flutter page to connect.

Some problems when running flutter project

  • When compiling and packaging, the relevant package could not be found, because the three default configuration places of flutter adopted the package of Google path.

  • Handling errors in Flutter(https://flutter.dev/docs/testing/errors

For example, to make your application quit immediately any time an error is shown in release mode, you could use the following handler:

import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {
  FlutterError.onError = (FlutterErrorDetails details) {
    FlutterError.dumpErrorToConsole(details);
    if (kReleaseMode)
      exit(1);
  };
  runApp(MyApp());
}
  • Flutter app error - getter 'value' was called on null

If you have created and assigned value to the variable and still it shows getter 'value' was called on null, try to Run or Restart your app instead of Hot Reload. Because Hot Reload will not call initstate() (where variables assign their values) which will be only called by Restarting the app.

  • Conflict of gradle version
What went wrong:
A problem occurred configuring project ':shared_preferences'.
> Could not resolve all artifacts for configuration ':shared_preferences:classpath'.
   > Could not resolve com.android.tools.build:gradle:3.4.0.

The build.gradle file in the Android root directory is configured as follows:

classpath 'com.android.tools.build:gradle:3.5.0

The version of the Android gradle plug-in for shared_preferences is not consistent with the version configured in the project. So you need to modify the Android gradle plug-in for shared_preferences to match the project.

The below is the directory:

flutter SDK directory\.pub-cache\hosted\pub.flutter-io.cn\shared_preferences-0.5.6+2\android\build.gradle

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末胸墙,一起剝皮案震驚了整個濱河市毅贮,隨后出現(xiàn)的幾起案子嘉栓,更是在濱河造成了極大的恐慌惊楼,老刑警劉巖抽米,帶你破解...
    沈念sama閱讀 218,640評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件特占,死亡現(xiàn)場離奇詭異,居然都是意外死亡云茸,警方通過查閱死者的電腦和手機是目,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,254評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來标捺,“玉大人懊纳,你說我怎么就攤上這事揉抵。” “怎么了嗤疯?”我有些...
    開封第一講書人閱讀 165,011評論 0 355
  • 文/不壞的土叔 我叫張陵冤今,是天一觀的道長。 經(jīng)常有香客問我茂缚,道長戏罢,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,755評論 1 294
  • 正文 為了忘掉前任脚囊,我火速辦了婚禮龟糕,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘悔耘。我一直安慰自己讲岁,他們只是感情好,可當我...
    茶點故事閱讀 67,774評論 6 392
  • 文/花漫 我一把揭開白布衬以。 她就那樣靜靜地躺著缓艳,像睡著了一般。 火紅的嫁衣襯著肌膚如雪看峻。 梳的紋絲不亂的頭發(fā)上阶淘,一...
    開封第一講書人閱讀 51,610評論 1 305
  • 那天,我揣著相機與錄音备籽,去河邊找鬼舶治。 笑死,一個胖子當著我的面吹牛车猬,可吹牛的內(nèi)容都是我干的霉猛。 我是一名探鬼主播,決...
    沈念sama閱讀 40,352評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼珠闰,長吁一口氣:“原來是場噩夢啊……” “哼惜浅!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起伏嗜,我...
    開封第一講書人閱讀 39,257評論 0 276
  • 序言:老撾萬榮一對情侶失蹤坛悉,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后承绸,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體裸影,經(jīng)...
    沈念sama閱讀 45,717評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,894評論 3 336
  • 正文 我和宋清朗相戀三年军熏,在試婚紗的時候發(fā)現(xiàn)自己被綠了轩猩。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,021評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖均践,靈堂內(nèi)的尸體忽然破棺而出晤锹,到底是詐尸還是另有隱情,我是刑警寧澤彤委,帶...
    沈念sama閱讀 35,735評論 5 346
  • 正文 年R本政府宣布鞭铆,位于F島的核電站,受9級特大地震影響焦影,放射性物質(zhì)發(fā)生泄漏车遂。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,354評論 3 330
  • 文/蒙蒙 一斯辰、第九天 我趴在偏房一處隱蔽的房頂上張望艰额。 院中可真熱鬧,春花似錦椒涯、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,936評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至狱意,卻和暖如春湖苞,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背详囤。 一陣腳步聲響...
    開封第一講書人閱讀 33,054評論 1 270
  • 我被黑心中介騙來泰國打工财骨, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人藏姐。 一個月前我還...
    沈念sama閱讀 48,224評論 3 371
  • 正文 我出身青樓隆箩,卻偏偏與公主長得像,于是被迫代替她去往敵國和親羔杨。 傳聞我的和親對象是個殘疾皇子捌臊,可洞房花燭夜當晚...
    茶點故事閱讀 44,974評論 2 355

推薦閱讀更多精彩內(nèi)容