native_drag_n_drop 0.0.1 copy "native_drag_n_drop: ^0.0.1" to clipboard
native_drag_n_drop: ^0.0.1 copied to clipboard

outdated

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

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:native_drag_n_drop/native_drag_n_drop.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool loadingData = false;
  List<DropData> receivedData = [];
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Drag and Drop Example'),
        ),
        body: SafeArea(
          child: Center(
            child: Column(
              children: [
                Expanded(
                  child: Stack(
                    children: [
                      NativeDropView(
                          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"),
                                ),
                          loadingCallback: (loading) {
                            setState(() {
                              loadingData = loading;
                            });
                          },
                          dataReceivedCallback: (data) {
                            setState(() {
                              receivedData.addAll(data);
                            });
                          }),
                      loadingData
                          ? const Center(
                              child: CircularProgressIndicator(),
                            )
                          : Container()
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
81
likes
0
pub points
53%
popularity

Publisher

verified publisheralexrabin.com

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on native_drag_n_drop