Curious George sees the world
 
Flet build App

Flet build App

寫完程式後,得利用 flet build 的命令來完成編譯,將程式碼打包成各平台所能執行的檔案,在 windows 環境下執行 flet build 和寫程式前,你應該先安裝 3 個程式:

  • git : https://git-scm.com/download/win flutter 使用 git 來做版本控制,在執行 flutter doctor 時,會自動使用 git 來更新 flutter 的版本,另外在專案初始化時的 flet create 也會使用 git 來進行版本控制
  • Android studio: https://developer.android.com/ 如果你不是要打包成 Android 的 app ,可忽略此安裝,安裝過程有很多的提示,大多採預設值,按下一步即可。
  • Flutter SDK: https://docs.flutter.dev/get-started/install/windows/mobile 這是最重要的一個, 整個 Flet 的靈魂,下載解壓縮後,裝檔案 copy 到你想要的位置,修改系統的 PATH就能使用,懶一點的直接到目錄下打開 flutter_console,這批次檔已自行定義 PATH, 在這 console 下也能完成之後的所有 command.整個安裝步驟請參考官方的說明。

撰寫程式

請先執行 flet create 來建立相關的程式

> flet create HelloWorld
Done!<
Run the app:
flet run HelloWorld   #之後要執行此程式,只要在現在的路徑下執行此命令即可

此命令產生出的目錄及檔案:

  • assets 目錄:放置程式所需的相關資源,像是字型或圖片等等
  • .gitignore 這是git的忽略清單
  • README.md 專案的說明書
  • main.py 程式的主要入口,flet 會從這裡開始執行你的程式
  • requirements.txt 這裡列出此專案所需的 python library, 請依實際狀況增減

編輯完檔案後,可執行 flet run HelloWorld 看到結果,沒問題後就能開始編程式了

編譯程式

flet build apk   # 編譯成 Android 的 apk
# 執行後 apk 檔會放在該路徑下的 build/apk 的目錄下

若想編譯成 web 的程式,將 apk 改成 web即可

flet build web # 編譯成 Web 的 app

想要直接試 run 一下程式只需在產生的 web 目錄下,執行 python -m http.server 8080,在browser 上打上 http://127.0.0.1:8080 就能看到結果


=== English Version ===

After writing the program, you must use the flet build command to complete the compilation and package the program code into files that can be run on any platform. Before running flet build and writing the program in the Windows environment, you should install 3 programs:

  • git : https://git-scm.com/download/win Flutter uses git for version control. When running flutter doctor, git is automatically used to update the flutter version. In addition, flet create will also use git for version control during project initialization.
  • Android studio: https://developer.android.com/ You can ignore this installation if you do not want to package it into an Android app.
  • Flutter SDK: https://docs.flutter.dev/get-started/install/windows/mobile This is the most important one, the soul of the entire Flet. After downloading and decompressing, install the file and copy it to the location you want. Modify the system PATH to use it. If you are lazy, go directly to the directory and open flutter_console. This batch of files has been Define PATH by yourself, and you can complete all subsequent commands under this console. Please refer to the official instructions for the entire installation steps.

Writing a Program

Please run flet create first to create the appropriate file and folder.

> flet create HelloWorld
Done!<
Run the app:
flet run HelloWorld   #之後要執行此程式,只要在現在的路徑下執行此命令即可

The folders and files generated by this command:

  • assets folder:Place related resources needed by the program, such as fonts or images, etc.
  • .gitignore gitignore file specifies intentionally untracked files that Git should ignore. 
  • README.md You can add a README file to your repository to tell other people why your project is useful, what they can do with your project, and how they can use it.
  • main.py is the entry point of your Flet application
  • requirements.txt is a standard pip file that contains the list of Python requirements for your Flet app

After editing the file, you can execute flet run HelloWorld to see the results. Once there are no problems, you can start programming.

Compiler

flet build apk   # Compile into Android apk
# The apk file under build/apk

If you want to compile it into a web program, just change apk to web

flet build web # Compile into Web app

If you want to run the program directly, just run python -m http.server 8080 in the generated web folder, type http://127.0.0.1:8080 in your browser and you will see the result.


發表迴響