desktop_drop 0.0.1 desktop_drop: ^0.0.1 copied to clipboard
A plugin which allow user drag files to you flutter application on desktop platforms.
desktop_drop #
A plugin which allow user drag files to you flutter application on desktop platforms.
Windows | ✅ |
Linux | ✅ |
macOS | ✅ |
Getting Started #
- Add
desktop_drop
to yourpubspec.yaml
.
desktop_drop: $latest_version
- Then you can use
DropTarget
to receive file drop events.
class ExmapleDragTarget extends StatefulWidget {
const ExmapleDragTarget({Key? key}) : super(key: key);
@override
_ExmapleDragTargetState createState() => _ExmapleDragTargetState();
}
class _ExmapleDragTargetState extends State<ExmapleDragTarget> {
final List<Uri> _list = [];
bool _dragging = false;
@override
Widget build(BuildContext context) {
return DropTarget(
onDragDone: (urls) {
setState(() {
for (final uri in urls) {
debugPrint("uri: ${uri.toFilePath()} "
"${File(uri.toFilePath()).existsSync()}");
}
_list.addAll(urls);
});
},
onDragEntered: () {
setState(() {
_dragging = true;
});
},
onDragExited: () {
setState(() {
_dragging = false;
});
},
child: Container(
height: 200,
width: 200,
color: _dragging ? Colors.blue.withOpacity(0.4) : Colors.black26,
child: _list.isEmpty
? const Center(child: Text("Drop here"))
: Text(_list.join("\n")),
),
);
}
}
LICENSE #
see LICENSE file