安裝Flutter SDK
從官網下載Linux版本SDK,解壓后配置環境變量:
echo 'export PATH="$PATH:/path/to/flutter/bin"' >> ~/.bashrc
source ~/.bashrc
驗證安裝:flutter --version。
安裝依賴工具
sudo apt install git curl wget unzip clang cmake build-essential
```。
添加插件
在項目根目錄的pubspec.yaml中添加依賴,例如:
dependencies:
http: ^0.13.3 # 替換為最新版本
運行flutter pub get安裝。
使用插件
在Dart代碼中導入并調用:
import 'package:http/http.dart' as http;
Future<void> fetchData() async {
final response = await http.get(Uri.parse('https://example.com'));
print(response.body);
}
```。
創建插件模板
flutter create --template=plugin my_plugin
cd my_plugin
編輯pubspec.yaml定義插件信息。
實現平臺通道
android/src/main/kotlin中編寫原生代碼,通過MethodChannel與Dart交互。ios/Classes中用Swift/Objective-C實現對應邏輯。測試與發布
運行flutter pub publish發布到pub.dev,或本地測試時直接引用路徑依賴。
flutter doctor檢查。