溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Flutter入門(mén)

發(fā)布時(shí)間:2020-09-28 19:16:30 來(lái)源:網(wǎng)絡(luò) 閱讀:1383 作者:屠夫章哥 欄目:移動(dòng)開(kāi)發(fā)

Dart語(yǔ)言中文網(wǎng)?http://dart.goodev.org/

Flutter官網(wǎng)?https://flutter.dev/

Flutter中文網(wǎng)? https://flutterchina.club/



一、windows環(huán)境搭建

  • 配置鏡像(加快FlutterSDK下載)? ? ? ?

????? ?官方寫(xiě)的這個(gè)export是用在linux上的

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

????? ?window上要將export換成set,但是去環(huán)境變量界面查看竟然沒(méi)有

????????Flutter入門(mén)

????????cmd 輸入set,會(huì)查看所有的環(huán)境變量,發(fā)現(xiàn)有設(shè)置的環(huán)境變量。


  • 下載FlutterSDK

    下載FlutterSDK,在path里配置“flutter\bin”的環(huán)境變量。

    執(zhí)行flutter doctor,下載FlutterSDK相關(guān)的依賴(lài)。

? ? ??

  • Android Studio上安裝Flutter和Dart插件

二、創(chuàng)建Flutter項(xiàng)目

  • 創(chuàng)建項(xiàng)目

??????Flutter入門(mén)

????????這里的flutter sdk path就是flutter文件夾位置

????????Flutter入門(mén)


???????*****和創(chuàng)建Android APP項(xiàng)目對(duì)比可發(fā)現(xiàn),沒(méi)有了minSdk、targetSdk這些個(gè)選項(xiàng)。(意思)

????????

  • 運(yùn)行項(xiàng)目

????? 首次運(yùn)行,可能會(huì)有以下錯(cuò)誤:

Launching?lib\main.dart?on?SM?N9009?in?debug?mode...
Initializing?gradle...
Finished?with?error:?ProcessException:?Process?"F:\Work\Flutter\flutter_app\android\gradlew.bat"?exited?abnormally:
Downloading?https://services.gradle.org/distributions/gradle-4.10.2-all.zip
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Exception?in?thread?"main"?javax.net.ssl.SSLException:?Connection?has?been?shutdown:?javax.net.ssl.SSLException:?java.net.SocketException:?Connection?reset
	at?sun.security.ssl.SSLSocketImpl.checkEOF(SSLSocketImpl.java:1551)
	at?sun.security.ssl.AppInputStream.available(AppInputStream.java:60)
	at?java.io.BufferedInputStream.available(BufferedInputStream.java:410)
	at?sun.net.www.MeteredStream.available(MeteredStream.java:170)
	at?sun.net.www.http.KeepAliveStream.close(KeepAliveStream.java:85)
	at?java.io.FilterInputStream.close(FilterInputStream.java:181)
	at?sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.close(HttpURLConnection.java:3448)
	at?org.gradle.wrapper.Download.downloadInternal(Download.java:77)
	at?org.gradle.wrapper.Download.download(Download.java:44)
	at?org.gradle.wrapper.Install$1.call(Install.java:61)
	at?org.gradle.wrapper.Install$1.call(Install.java:48)
	at?org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
	at?org.gradle.wrapper.Install.createDist(Install.java:48)
	at?org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
	at?org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Caused?by:?javax.net.ssl.SSLException:?java.net.SocketException:?Connection?reset
	at?sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
	at?sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
	at?sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1916)
	at?sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1880)
	at?sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1825)
	at?sun.security.ssl.AppInputStream.read(AppInputStream.java:116)
	at?java.io.BufferedInputStream.read1(BufferedInputStream.java:284)
	at?java.io.BufferedInputStream.read(BufferedInputStream.java:345)
	at?sun.net.www.MeteredStream.read(MeteredStream.java:134)
	at?java.io.FilterInputStream.read(FilterInputStream.java:133)
	at?sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3375)
	at?sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3368)
	at?org.gradle.wrapper.Download.downloadInternal(Download.java:62)
	...?7?more
Caused?by:?java.net.SocketException:?Connection?reset
	at?java.net.SocketInputStream.read(SocketInputStream.java:210)
	at?java.net.SocketInputStream.read(SocketInputStream.java:141)
	at?sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
	at?sun.security.ssl.InputRecord.readV3Record(InputRecord.java:593)
	at?sun.security.ssl.InputRecord.read(InputRecord.java:532)
	at?sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
	at?sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
	at?sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
	...?14?more
??Command:?F:\Work\Flutter\flutter_app\android\gradlew.bat?-v

? ? 這個(gè)是在下載gradle,網(wǎng)絡(luò)不好的原因。如果網(wǎng)絡(luò)好了,run會(huì)自動(dòng)下載gradle,run成功之后,控制臺(tái)會(huì)顯示:

????Launching?lib\main.dart?on?SM?N9009?in?debug?mode...
Initializing?gradle...
Resolving?dependencies...
[{"event":"app.progress","params":{"appId":"d62136c6-30c8-4426-8e6e-e1ec5bdf918e","id":"2","progressId":null,"message":"Running?Gradle?task?'assembleDebug'..."}}]Running?Gradle?task?'assembleDebug'...

Built?build\app\outputs\apk\debug\app-debug.apk.
Installing?build\app\outputs\apk\app.apk...
[{"event":"app.progress","params":{"appId":"d62136c6-30c8-4426-8e6e-e1ec5bdf918e","id":"4","progressId":null,"message":"Syncing?files?to?device?SM?N9009..."}}]Syncing?files?to?device?SM?N9009...

?? ? 趕緊體驗(yàn)了一把“熱重載”特性,實(shí)在是非常爽!?。?/p>

? ? ?另外,通過(guò)控制臺(tái)日志可以發(fā)現(xiàn):

Launching?lib\main.dart?on?SM?N9009?in?debug?mode...
Initializing?gradle...
Resolving?dependencies...
Running?Gradle?task?'assembleDebug'...
Built?build\app\outputs\apk\debug\app-debug.apk.
Installing?build\app\outputs\apk\app.apk...
Syncing?files?to?device?SM?N9009...

????? 項(xiàng)目第一次run的時(shí)候,也會(huì)生成apk文件。

  • ?打開(kāi)項(xiàng)目出現(xiàn)一直提示加載的問(wèn)題? ??

? ? ? ?Android Studio使用flutter upgrade等時(shí)提示waiting for another flutter command to release the startup lock

????? 解決辦法:

????先打開(kāi)任務(wù)管理器,結(jié)束掉所有dart.exe。然后打開(kāi)你的flutter安裝文件夾,找到\bin\cache中的lockfile文件刪除。之后重啟Android?Studio。

????????????????????

  • 依賴(lài)package

????? ?****更新yaml文件之后,點(diǎn)擊Packages get,即可將包下載下來(lái)。

????? ?Flutter入門(mén)

????????然后在dart里import

????????

???????****?yaml文件,點(diǎn)擊Get dependencies,會(huì)報(bào)下面的錯(cuò)誤,不用管就行。

Working?dir:?F:\Work\Flutter\startup_namer
G:\Android\flutter_windows_v1.7.8+hotfix.4-stable\flutter\bin\cache\dart-sdk\bin\pub.bat?upgrade
Resolving?dependencies...
Because?startup_namer?depends?on?flutter_test?any?from?sdk?which?doesn't?exist?(the?Flutter?SDK?is?not?available),?version?solving?failed.

Flutter?users?should?run?`flutter?pub?get`?instead?of?`pub?get`.
Process?finished?with?exit?code?69

????? ? ? ??

? ? ?????


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI