引入包 flutter_dropzone: ^4.2.1
DropzoneView(
              operation: DragOperation.copy,
              cursor: CursorType.grab,
              onCreated: (ctrl) => controller1 = ctrl,
              onLoaded: () => print('Zone 1 loaded'),
              onError: (error) => print('Zone 1 error: $error'),
              onHover: () {
                // setState(() => highlighted1 = true);
                print('Zone 1 hovered');
              },
              onLeave: () {
                // setState(() => highlighted1 = false);
                print('Zone 1 left');
              },
              onDropFile: (file) async {
                print('Zone 1 drop: ${file.name}');
                setState(() {
                  //  message1 = '${file.name} dropped';
                  //   highlighted1 = false;
                });
                final bytes = await controller1.getFileData(file);
                print('Read bytes with length ${bytes.length}');
                // 读取到了文件内容
                setState(() {
                  images.add(bytes);
                });
                // print(bytes.sublist(0, min(bytes.length, 20)));
              },
              onDropString: (s) {
                print('Zone 1 drop: $s');
                setState(() {
                  // message1 = 'text dropped';
                  //  highlighted1 = false;
                });
                //print(s.substring(0, min(s.length, 20)));
              },
              onDropInvalid: (mime) => print('Zone 1 invalid MIME: $mime'),
              onDropFiles: (files) => print('Zone 1 drop multiple: $files'),
              onDropStrings: (strings) => print('Zone 1 drop multiple: $strings'),
            ),

标签: none