搜尋套件、儲存庫與 APP 分類

套件詳情v1.2.2

dropbox_client

適用於 Flutter 的 Dropbox 客戶端。此程式庫支援 Android 與 iOS。授權可透過 Dropbox 應用程式或外部網頁瀏覽器進行。

AndroidiOS
近 30 天下載
487
喜歡數
42
Pub 分數
140

安裝套件

flutter pub add dropbox_client

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供與 Dropbox API 互動的客戶端,讓 Android 和 iOS 應用程式能夠管理 Dropbox 中的檔案和資料夾。它支援透過 Dropbox 應用程式或外部網頁瀏覽器進行驗證,確保對使用者帳戶的安全存取。此函式庫設計為可輕鬆整合至需要雲端儲存功能的行動應用程式。它簡化了上傳、下載及列出檔案等常見作業,非常適合開發具備 Dropbox 連線功能的跨平台應用程式的開發者。

適用情境

  • 檔案備份和同步
  • 雲端文件儲存
  • 用戶檔案管理
  • 應用資料持久化
  • 與 Dropbox 工作流程整合

主要特色

  • 支援 Android 和 iOS
  • 透過 Dropbox 應用程式或瀏覽器進行驗證
  • 簡單檔案上傳/下載
  • 跨平台相容性
  • 安全的 OAuth2 授權

適合對象

  • 需要雲端儲存的行動應用程式
  • 需要用戶文件訪問權限的應用
  • 使用 Dropbox 作為後端的開發者
  • 具有雲需求的Flutter專案
  • 同時針對 Android 和 iOS 的應用

使用建議

  • 需要 Dropbox 應用程式或瀏覽器進行驗證
  • 僅限 Dropbox 生態系統
  • 需要對網路問題進行適當的錯誤處理
  • 依賴外部 Dropbox API 的穩定性
  • 可能需要使用者同意才能存取檔案

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

dropbox client

pub package

A flutter plugin for accessing Dropbox.

Setup

Register a Dropbox API app from https://www.dropbox.com/developers . You need a Dropbox app key. Public clients using PKCE do not need an app secret, and must not embed one in the application.

For Android, add below in AndroidManifest.xml (replace DROPBOXKEY with your key)

    <activity
        android:name="com.dropbox.core.android.AuthActivity"
        android:configChanges="orientation|keyboard"
        android:launchMode="singleTask">
        <intent-filter>

            <!-- Change this to be db- followed by your app key -->
            <data android:scheme="db-DROPBOXKEY" />

            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

If you need more help setting up Android, please read https://github.com/dropbox/dropbox-sdk-java#setup .

For iOS,

  1. add below in Info.plist

     <key>LSApplicationQueriesSchemes</key>
       <array>
           <string>dbapi-8-emm</string>
           <string>dbapi-2</string>
       </array>
    
  2. add below in Info.plist (replace DROPBOXKEY with your key)

     <key>CFBundleURLTypes</key>
       <array>
         <dict>
           <key>CFBundleURLSchemes</key>
           <array>
             <string>db-DROPBOXKEY</string>
           </array>
           <key>CFBundleURLName</key>
           <string></string>
         </dict>
       </array>
    

3.a) If you are using Swift, add below code to AppDelegate.swift

    import ObjectiveDropboxOfficial

    // should be inside AppDelegate class
    override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
      if let authResult = DBClientsManager.handleRedirectURL(url) {
          if authResult.isSuccess() {
              print("dropbox auth success")
          } else if (authResult.isCancel()) {
              print("dropbox auth cancel")
          } else if (authResult.isError()) {
              print("dropbox auth error \(authResult.errorDescription)")
          }
      }
      return true
    }

    // if your are linked with ObjectiveDropboxOfficial 6.x use below code instead

    override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
      DBClientsManager.handleRedirectURL(url, completion:{ (authResult) in
        if let authResult = authResult {
            if authResult.isSuccess() {
                print("dropbox auth success")
            } else if (authResult.isCancel()) {
                print("dropbox auth cancel")
            } else if (authResult.isError()) {
                print("dropbox auth error \(authResult.errorDescription)")
            }
        }
      });
      return true
    }

3.b) If you are using Objective C, add below code to AppDelegate.m

    #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>

    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
        options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
      DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
      if (authResult != nil) {
        if ([authResult isSuccess]) {
          NSLog(@"Success! User is logged into Dropbox.");
        } else if ([authResult isCancel]) {
          NSLog(@"Authorization flow was manually canceled by user!");
        } else if ([authResult isError]) {
          NSLog(@"Error: %@", authResult);
        }
      }
      return NO;          
    }

    // if your are linked with ObjectiveDropboxOfficial 6.x use below code instead

    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
        options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
      BOOL result = [DBClientsManager handleRedirectURL:url completion: ^(DBOAuthResult *authResult) {
        if (authResult != nil) {
          if ([authResult isSuccess]) {
            NSLog(@"Success! User is logged into Dropbox.");
          } else if ([authResult isCancel]) {
            NSLog(@"Authorization flow was manually canceled by user!");
          } else if ([authResult isError]) {
            NSLog(@"Error: %@", authResult);
          }
        }
      }];
      return NO;          
    }
  1. Update Deployment Target to iOS 9.0 or above from Xcode. (dropbox_client 0.7.0 and above)

  2. Add below permissions to your app from Dropbox App Console:

  • files.metadata.read
  • files.metadata.write
  • files.content.read
  • files.content.write

If you need more help setting up for iOS, please read https://github.com/dropbox/dropbox-sdk-obj-c#get-started .

Usage

import 'package:dropbox_client/dropbox_client.dart';

Future initDropbox() async {
    // Initialize a public client for PKCE. Call only once.
    await Dropbox.init(dropbox_clientId, dropbox_key);
}

The optional third argument is retained for legacy confidential-client flows:

await Dropbox.init(dropbox_clientId, dropbox_key, dropbox_secret);
// Legacy Authorization
String accessToken;

Future testLogin() async {
  // this will run Dropbox app if possible, if not it will run authorization using a web browser.
  await Dropbox.authorize();
}

Future getAccessToken() async {
  accessToken = await Dropbox.getAccessToken();
}

Future loginWithAccessToken() async {
  await Dropbox.authorizeWithAccessToken(accessToken);
}

Future testLogout() async {
  // unlink removes authorization
  await Dropbox.unlink();
}
// OAuth 2 code flow with PKCE that grants a short-lived token
String credentials;

Future testLogin() async {
  // this will run Dropbox app if possible, if not it will run authorization using a web browser.
  await Dropbox.authorizePKCE();
}

Future getCredentials() async {
  credentials = await Dropbox.getCredentials();
}

Future loginWithCredentials() async {
  await Dropbox.authorizeWithCredentials(credentials);
}

Future testLogout() async {
  // unlink removes authorization
  await Dropbox.unlink();
}
// List / Upload / Download

Future testListFolder() async {
  final result = await Dropbox.listFolder(''); // list root folder
  print(result);
  
  final url = await Dropbox.getTemporaryLink('/file.txt');
  print(url);
}

Future testUpload() async {
  final filepath = '/path/to/local/file.txt';
  final result = await Dropbox.upload(filepath, '/file.txt', (uploaded, total) {
    print('progress $uploaded / $total');
  });
}

Future testDownload() async {
  final filepath = '/path/to/local/file.txt';
  final result = await Dropbox.download('/dropbox_file.txt', filepath, (downloaded, total) {
    print('progress $downloaded / $total');
  });
}

Example can be found in example folder.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。