パッケージ、リポジトリ、アプリカテゴリを検索

GitHub リポジトリalexrabin/FlutterNativeDragAndDrop

FlutterNativeDragAndDrop

アプリにネイティブなドラッグアンドドロップ機能を追加できるFlutterパッケージです。

FlutterNativeDragAndDrop のプロジェクト画像
スター
24
フォーク
2
最終プッシュ(UTC)
2023/01/12
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

native_drag_n_drop

native_drag_n_drop Donate Buy me a coffee GitHub issues GitHub Repo stars

A package that allows you to add native drag and drop support into your flutter app.

Like tutorials? Follow one along here iPadDropExample

Currently supported features

  • Support iPadOS 11, iOS 15, and Android 8.0 and above
  • Only has drop support (can drag data from outside of the app and drop into your flutter application)
  • Supports text, urls, images, videos, audio, pdfs, and custom file extensions
  • Can drop multiple items at once
  • Can add allowed number of items to be dragged at a time (iOS only. Android doesn't have this capability)

Usage

import 'package:native_drag_n_drop/native_drag_n_drop.dart';

List<DropData> receivedData = [];

@override
Widget build(BuildContext context) {
    return NativeDropView(
    allowedTotal: 5, //Allowed total only works on iOS (Android has limitations)
    allowedDropDataTypes: const [DropDataType.text, DropDataType.image, DropDataType.video],
    allowedDropFileExtensions: ['apk', 'dart'],
    receiveNonAllowedItems: false,
    child: receivedData.isNotEmpty
        ? ListView.builder(
            itemCount: receivedData.length,
            itemBuilder: (context, index) {
                var data = receivedData[index];
                if (data.type == DropDataType.text) {
                    return ListTile(
                    title: Text(data.dropText!),
                    );
                }

                return ListTile(
                    title: Text(data.dropFile!.path),
                );
            })
        : const Center(
            child: Text("Drop data here"),
        ),
    loading: (loading) {
        // display loading indicator / hide loading indicator
    },
    dataReceived: (List<DropData> data) {
        setState(() {
            receivedData.addAll(data);
        });
    });
}

The dataReceived callback returns List<DropData>.

enum DropDataType { text, url, image, video, audio, pdf, file}

class DropData {
  File? dropFile;
  String? dropText;
  Map<String, dynamic>? metadata;
  DropDataType type;
  DropData({this.dropFile, this.dropText, this.metadata, required this.type});
}

It is safe to assume that if the dataType is text or url then the dropText will be non null.

As for image, video, audio, pdf, file it is safe to assume the dropFile will be non null

All files are saved to the temp directory on the device so if you want to save the file to the device copy its data to a file in the documents directory.

Todo

  • [x] specify the number of items allowed to be dropped at a time
  • [x] Only allow certain data types
  • [x] Android Support
  • [ ] Drag support (Dragging data within app to a source outside of flutter app)
Alex Rabin GitHub avatar
GitHub 作者

Alex Rabin ↗

Full stack dev currently working on SupDesk

言語DartSwiftJavaRubyObjective-C

カテゴリー

使用している依存関係

依存関係一覧 3 件

  • flutter{"sdk":"flutter"}
  • flutter_test開発用{"sdk":"flutter"}
  • flutter_lints開発用^1.0.0

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗