drop_zone 1.0.2 copy "drop_zone: ^1.0.2" to clipboard
drop_zone: ^1.0.2 copied to clipboard

Platformweb

A simple way to bring drag’n’drop to flutter web. drop_zone is commonly used for file choosing by dragging and dropping a file(s) onto a designated widget. The user can then use the dropped html file(s).

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:drop_zone/drop_zone.dart';
// ignore: avoid_web_libraries_in_flutter
import 'dart:html' as html;

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String dropzoneState = '';
  String dropzoneState2 = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            DropZone(
              onDragEnter: () {
                print('drag enter');
                setState(() {
                  dropzoneState = 'drag enter';
                });
              },
              onDragExit: () {
                print('drag exit');
                setState(() {
                  dropzoneState = 'drag exit';
                });
              },
              onDrop: (List<html.File> files) {
                print('files dropped');
                print(files);
                setState(() {
                  dropzoneState = 'files dropped $files';
                });
              },
              child: Container(
                decoration: BoxDecoration(border: Border.all()),
                width: 300,
                height: 300,
              ),
            ),
            Text(dropzoneState),
            DropZone(
              onDragEnter: () {
                print('drag enter');
                setState(() {
                  dropzoneState2 = 'drag enter';
                });
              },
              onDragExit: () {
                print('drag exit');
                setState(() {
                  dropzoneState2 = 'drag exit';
                });
              },
              onDrop: (List<html.File> files) {
                print('files dropped');
                print(files);
                setState(() {
                  dropzoneState2 = 'files dropped $files';
                });
              },
              child: Container(
                decoration: BoxDecoration(border: Border.all()),
                width: 300,
                height: 300,
              ),
            ),
            Text(dropzoneState2),
          ],
        ),
      ),
    );
  }
}
44
likes
140
points
48.1k
downloads

Publisher

unverified uploader

Weekly Downloads

A simple way to bring drag’n’drop to flutter web. drop_zone is commonly used for file choosing by dragging and dropping a file(s) onto a designated widget. The user can then use the dropped html file(s).

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on drop_zone