---
# System prepended metadata

title: flutter sprint
tags: ['202205', flutter]

---

{%hackmd DfWYF9cYREebVNN1eEOz-w %}

flutter sprint
======

> ***不知自己不知道, 那你會以為你知道.***

###### tags: `flutter` `202205`

前言
------
Flutter 跟 Dart 的關係，Flutter 是框架(內含專用的Library、widget)，而 Dart 則是程式語言。 有點像 Python 與 Django 的關係

特點是性能好一點、UI AS Code(Widget)

## 環境設定

### 安裝最新穩定版本
``` bash
$ git clone -b stable https://github.com/flutter/flutter.git
```

### 環境變數中設定路徑 **~\flutter\bin**
``` bash
# 檢查 SDK
$ where flutter dart

# 驗證與安裝依賴
$ flutter doctor
```

### 透過 android sdk manager install cmd tool
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
:::info
如果執行失敗先確認環境變數是否正確，確認執行權限是否足夠。

若真的不行則開啟 android studio 的 sdk manager，左側選單找 Android SDK => menu brar 找 SDK Tool 並勾選 "show package details"，接著從清單中勾選 **"Android studio Command-line Tools(tools)"**，並按下 apply & OK
:::

### Open an elevated console window and run the following command to begin signing licenses
```bash
$ flutter doctor --android-licenses
```

### 安裝 Flutter 和 dart plugin
- Flutter
- Flutter Snippts

### 開啟 flutter 專案
ref: [開啟專案時出現 Dart SDK is not Configiured ](https://www.flutterbeads.com/dart-sdk-is-not-configured

Here are the steps to fix the Error:
1. Open the terminal (in Mac/Linux) or command prompt (Windows)
2. Write which flutter. Copy the Flutter installation path.
3. Open Android Studio,
4. For Windows/Linux: Go to File->Settings->Language & Framework->Dart.
5. cache/dart-sdk. So it should look something like this C:\flutter\bin\cache\dart-sdk
6. 下方勾選對應的專案或 modular
7. Click Apply.
8. Click OK.

## Firbase

### Add Firebase to your Android app
- 進入flutter目錄底下 /android/app/build.grandle 找到defaultConfig下的 applicationId 複製下來
- Install keytool on your system
    - java jdk 8 => jdk-8u333-windows-x64
- Debug signing certificate SHA-1 (optional)
    - 
    ```bash
    $ keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
    ``` 
    - password: android
    - get SHA-1 and copy to firbase
- 在 firbase 專案開啟 Realtime Database 並啟用測試模式(一個月)
```json
{
  "rules": {
    ".read": "now < 1656259200000",  // 2022-6-27
    ".write": "now < 1656259200000",  // 2022-6-27
  }
}
```
- 將 google-servces.json 下載並放入 /android/app/ 資料夾下
- Add Firebase SDK
    - Project-level build.gradle => add line to dependencies scope
        - classpath 'com.google.gms:google-services:4.3.10'
    - App-level build.gradle => add line to root
        - apply plugin: 'com.google.gms.google-services'
- 進入專案目錄底下的 pubspec.yaml set => firebase_database: ^9.0.14


